Talk:Python Programming/RegEx

Latest comment: 4 years ago by Dave Braunschweig in topic Meaning of '.'

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                                                                                                                                        
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
Return to "Python Programming/RegEx" page.