且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python 中的正则表达式反向引用问题

更新时间:2022-11-14 18:36:52

你必须将字符串标记为原始字符串,因为 \ 在那里,通过放置一个 r 在正则表达式前:

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