Python
- 6 ответов
- 0 вопросов
4
Вклад в тег
import re
num_finder = re.compile('(?:(\d{1,10})\shours?)?(?:\s?(\d{1,2})\smins?)?(?:\s?(\d{1,2}))?')
search_result = num_finder.match(value_goes_here)
hours = int(search_result.group(1)) if search_result.group(1) else 0
mins = int(search_result.group(2)) if search_result.group(2) else 0
secs = int(search_result.group(3)) if search_result.group(3) else 0
seconds_passed = hours * 3600 + mins * 60 + secs