How to match a period with regex in Python

Matching a period within a string with regex uses a regular expression to match the period in the string.

Solution for How to match a period with regex in Python : You can use the escape character \ to match a period with regex Use the pattern \. within a regular expression to match a literal period since, by default, the dot . is a metacharacter in regex that matches any character except a newline. Call re.search(pattern, string) with pattern as r”\.” to return a MatchObject if string contains a period.


how-to-match-a-period-with-regex-in-python