I want to extract this kind of data from a time value with some regex:
1h 34mn 2s >>> [1,34,2]
1h 4mn >>> [1,4]
34mn 2s >>> [34,2]
34s >>> [34]
I tryed :
re.match(r'((.*)h)?((.*)mn)?((.*)s)?', '1h 34mn').groups()
('1h', '1', ' 34mn', ' 34', None, None)
Almost done but still not what I’m looking for.
Edit:
I need to extract total value in seconds 1h 34mn 2s >>> 1*3600+34*60+2
Well, if all you just want is seconds, and aren’t too worried that hours precedes minutes, and minutes precedes seconds, as long as they’re qualified (ie, ‘1s 9h 32m’ is valid), you could use: