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'
r'''this is wrong'''
. The right syntax must use r with double-quotes:r"""this is right"""
. See How to correctly write a raw multiline string in Python? – Verboten