Python regex compile (with re.VERBOSE) not working

后端 未结 1 755
不思量自难忘°
不思量自难忘° 2020-12-17 22:42

I\'m trying to put comments in when compiling a regex but when using the re.VERBOSE flag I get no matchresult anymore.

(using Python 3.3.0)

Before:



        
相关标签:
1条回答
  • 2020-12-17 23:14

    Whitespaces are ignored (ie, your expression is effectively DukeWann), so you need to make sure there's a space there:

    regex = re.compile(r'''
    Duke[ ] # First name followed by a space
    Wann #Last Name
    ''', re.VERBOSE | re.IGNORECASE)
    

    See http://docs.python.org/2/library/re.html#re.VERBOSE

    0 讨论(0)
提交回复
热议问题