tests = ['1m30s', '3m15s', '2m25s', '2m', '55s']
for time_str in tests:
    match = re.match('(?:(\\d*)m)?(?:(\\d*)s)?', time_str)
if match:
    minutes = int(match.group(1) or 0)
seconds = int(match.group(2) or 0)
print({'minutes': minutes, 'seconds': seconds})
Parsing 'time string' with Python?