Python regex compile (with re.VERBOSE) not working
Posted
by
bfloriang
on Stack Overflow
See other posts from Stack Overflow
or by bfloriang
Published on 2012-12-07T10:58:41Z
Indexed on
2012/12/07
11:03 UTC
Read the original article
Hit count: 417
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", re.IGNORECASE)
print(regex.search("He is called: Duke WAnn.").group())
Output: Duke WAnn
After:
regex = re.compile(r'''
Duke # First name
Wann #Last Name
''', re.VERBOSE | re.IGNORECASE)
print(regex.search("He is called: Duke WAnn.").group())`
Output: AttributeError: 'NoneType' object has no attribute 'group'
© Stack Overflow or respective owner