Home > Article > Backend Development > How to Match a Literal Dot in a Regular Expression with Python?
Matching a Literal Dot with Regular Expressions
In Python, matching a literal dot (.) using raw strings (e.g., r"string") requires escaping to avoid treating it as a metacharacter that matches any character.
To match the string "test.this" from the input "blah blah blah [email protected] blah blah", you can use the following regular expression:
import re pattern = r"\b\w\.\w@.*" match = re.findall(pattern, "blah blah blah [email protected] blah blah") print(match)
Here's a breakdown of the regular expression:
The re.findall() function returns a list of all matching substrings in the input string. In this case, it will return a list containing the matched string "test.this@...".
The above is the detailed content of How to Match a Literal Dot in a Regular Expression with Python?. For more information, please follow other related articles on the PHP Chinese website!