Use search
instead of match
for test in tests:... m = re.search ("\(d.(.*)\)", test)... if m:... print(m.groups())... (' October 9, 1999',)(' December 28, 1991',)
Why match
wont work?
Tha match
searches the pattern at the start of the string. In the test string, the matched part is not at the start of the string and hence match
fails. Where as search
searches for the pattern anywhere in the string.
re.search(pattern, string, flags=0)
Scan through string looking for the first location where the regular expression pattern produces a match, and return a corresponding MatchObject instance. Return None if no position in the string matches the pattern;