Talk:Python Programming/RegEx

From Wikiversity
Jump to navigation Jump to search

Meaning of '.'[edit]

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                                                                                                                                        
match = re.match(".*", string)
if match:
    print("start:", match.start(0))
    print("end:", match.end(0))
start: 0
end: 5
group: line1

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

@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)