re.search - example
import re
print('re: search')
print('-' * 30, '\n')
time_str = 'some 1:02:34.05 time'
time_str = 'some time'
time_str = 'some 34 time'
res = re.search('([\:\d]+)[\.,](\d+)', time_str)
if res:
print('res =',res)
print('res.string =',res.string)
print('res.groups() =',res.groups())
print('res.group(0) =',res.group(0))
print('res.group(1) =',res.group(1))
print('res.group(2) =',res.group(2))
print('res.lastindex =',res.lastindex)
else:
print('not found')
Last updated