Regex Problem Group Name Redefinition?

后端 未结 3 1070
情书的邮戳
情书的邮戳 2021-02-05 17:32

So I have this regex:

(^(\\s+)?(?P(\\w)(\\d{7}))((01f\\.foo)|(\\.bar|\\.goo\\.moo\\.roo))$|(^(\\s+)?(?PR1_\\d{6}_\\d{6}_)((01f\\.foo)|(\         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-02-05 18:04

    The following answer deals with how to make the above regex work in Python3.

    Since the re2 module as suggested by Max would not work in Python3, because of the NameError: basestring. Another alternative to this is the regex module.

    regex module is just an enhanced version of re with extra added features. This module also allows to have same group names in the regex.

    You can install it via:

    sudo pip install regex
    

    And if you have already been using re or re2 in your program. Just do the following to import regex module

    import regex as re
    

提交回复
热议问题