import re
regex = re.compile(r"休憩\D{0,10}(\d*\.\d?|\d+)", flags=re.MULTILINE)
test_str = ("休憩時間11.4時間\n"
"休憩 4 時間\n"
"休憩時間:0.05\n"
"休憩:0.\n"
"休憩時間:0.2\n"
"休憩:11.52\n"
"休憩タイム 2時間\n"
"休憩時間: 0 時間\n"
"やすみ 4時間\n"
"休憩:なし 携帯 90\n"
"休憩と十日有休をくれ 2時間")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html