Talk:Python Programming/RegEx

From Wikiversity
Jump to navigation Jump to search

Meaning of '.'[edit source]

Under summary there is the statement:

In regex, . matches any single character.

My version of python3.6 on Mac excludes new line.

import re

string = """line1                                                                                                                                        
line2                                                                                                                                                    
line3                                                                                                                                                    
"""
match = re.match(".*", string)
if match:
    print("start:", match.start(0))
    print("end:", match.end(0))
    print("group:", match.group(0))
start: 0
end: 5
group: line1

ThaniosAkro (discusscontribs) 09:33, 25 October 2019 (UTC)[reply]

@ThaniosAkro: You are correct. "." matches every single character except newline, unless the DOTALL flag is used. [1] -- Dave Braunschweig (discusscontribs) 13:08, 25 October 2019 (UTC)[reply]