Issue with regex backreference in Python

后端 未结 1 1636
清歌不尽
清歌不尽 2021-01-24 03:10

I am not sure why this is not working. Perhaps I am missing something with Python regex.

Here is my regex and an example string of what I want it to match too:



        
相关标签:
1条回答
  • 2021-01-24 03:24

    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>")
    
    0 讨论(0)
提交回复
热议问题