the_regex = re.compile("(\d\d-(?:0[1-9]|[1-9]\d))")
l = re.findall(the_regex, '11-01 11-99 10-29 01-99 00-00 11-00')
print l
shows:
['11-01', '11-99', '10-29', '01-99']
if you use re.finditer, it returns a generator that might be better for you:
it = re.finditer(the_regex, '11-01 11-99 10-29 01-99 00-00 11-00')
print type(it)
print list(i.group(0) for i in it)
shows it:
<type 'callable-iterator'>
['11-01', '11-99', '10-29', '01-99']
source
share