import re
text = "a.b a-b a b" # Example string
# Using unescaped dot: matches any character
matches_any_char = re.findall(r"a.b", text)
# Using escaped dot: matches only "a.b"
matches_literal_dot = re.findall(r"a\.b", text)
''' BTW,
The string \"a\\.b\" in Python is interpreted as "a\.b", where:
\" escapes the double quotes,
\\. escapes \ before . (dot)
'''
print("Matches for \"a.b\":", matches_any_char)
print("Matches for \"a\\.b\":", matches_literal_dot)
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.