I’m reading Dive into Python 3 about regular expressions and specifically using re.VERBOSE. I tried searching for a string, but it always returns “None”. For example:
import re
pattern = '''
testing
'''
print(re.search(pattern, 'test', re.VERBOSE))
I had thought that this should return something other than None because the pattern of characters “test” exists in “testing”. I had also thought that if it had been something like:
pattern = '''
^testing$
'''
Then it makes sense that I would get a return value of None if I searched for the same string. However, regardless, I always seem to get a return value of None. What am I doing wrong?
You have your patterns and text-to-search mixed up.
You are looking for
testingin texttest, and the latter is not nearly long enough. 🙂If you reversed the two (pattern
test, texttesting) things work: