You have to mark the string as a raw string, due to the \
in there, by putting an r
in front of the regex:
m = re.match(r"<(.*)>phone</\1>", "<bar>phone</bar>")
More Related Contents:
- Searching for IP addresses in a file
- Finding the longest substring of consecutive letters in python
- How to use a variable inside a regular expression?
- Regular expression to return text between parenthesis
- How to match any string from a list of strings in regular expressions in python?
- Regex matching between two strings?
- Python regex for unicode capitalized words
- Regular expression parsing a binary file?
- FutureWarning: The default value of regex will change from True to False in a future version
- match dates using python regular expressions
- Python TypeError on regex [duplicate]
- Convert bytes to a string
- Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?
- How do I use raw_input in Python 3
- How to install pip with Python 3?
- Find all combinations of a list of numbers with a given sum
- Use Python’s string.replace vs re.sub
- numpy is already installed with Anaconda but I get an ImportError (DLL load failed: The specified module could not be found)
- How do I return a string from a regex match in python? [duplicate]
- How can I split a string of a mathematical expressions in python?
- How to access class (static) variables in Python?
- Extract the ‘src’ attribute from an ‘img’ tag using Beautiful Soup
- Invalid Syntax error when running python from inside Visual Studio Code
- Regular expression to return all characters between two special characters
- Python mock Patch os.environ and return value
- Django viewset has not attribute ‘get_extra_actions’
- Type error Unhashable type:set
- Import libraries in lambda layers
- ‘NoneType’ object is not subscriptable?
- Python CGI – UTF-8 doesn’t work