Jump to content

Talk:Python Programming/RegEx

Page contents not supported in other languages.
Add topic
From Wikiversity
Latest comment: 5 years ago by Dave Braunschweig in topic Meaning of '.'

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