Issue with regex backreference in Python

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>")

Leave a Comment