Skip to content Skip to sidebar Skip to footer

Python Regex Compile (with Re.verbose) Not Working

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: regex = re.compile(r'Duke wann',

Solution 1:

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

Post a Comment for "Python Regex Compile (with Re.verbose) Not Working"