Home > Article > Backend Development > How to Extract a Substring with Dots Using Regular Expressions in Python?
Matching Dots with Regular Expressions
The task at hand is to identify and extract the substring "test.this" from the provided string "blah blah blah [email protected] blah blah". In Python, this can be achieved using regular expressions.
Regular Expression for Matching Dots
In regular expressions, a dot (.) denotes a wildcard character, matching any single character. However, when attempting to match a literal dot, it must be escaped using the backslash character () in a raw Python string.
The following regular expression can be used to accomplish the task:
import re match = re.search(r"\b\w.\w@.*?", "blah blah blah [email protected] blah blah") if match: print(match.group())
Explanation:
The above is the detailed content of How to Extract a Substring with Dots Using Regular Expressions in Python?. For more information, please follow other related articles on the PHP Chinese website!