简体   繁体   中英

Issue with regex backreference in Python

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:

    PHONE_REGEX        = "<(.*)>phone</\1>"
    EXAMPLE            = "<bar>phone</bar>"

I tested this match in isolation and it failed. I used an online regex tester and it matched. Am I simply missing something that is particular to Python regex?

Thanks!

由于\\在那里,您必须将字符串标记为原始字符串,方法是将r放在正则表达式的前面:

m = re.match(r"<(.*)>phone</\1>", "<bar>phone</bar>")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM