import re
regex = re.compile(r"all\s+(\S+\s+){2}(?<field1>[\d\.]+)", flags=re.MULTILINE)
test_str = (" 10/1/2017 0:10:01 all 9.13 0 1.68 6.6 0 82.59\n"
" 10/1/2017 0:20:01 all 7.46 0 0 5.74 0 85.17\n"
" 10/1/2017 0:30:01 all 9.05 0 129 1.53 0 88.13\n"
" 10/1/2017 0:40:01 all 7.77 0 1.45 1.23 0 89.54\n"
" 10/1/2017 0:50:01 all 7.08 0 1.5 1.41 0 90.02\n"
" 10/1/2017 1:00:01 all 6.46 0 1.43 1.82 0 90.29\n"
" 10/1/2017 1:10:01 all 45.4 0 4.2 29.27 0 21.13\n"
" 10/1/2017 1:20:01 all 61.74 0 4.74 31.19 0 2.32\n"
" 10/1/2017 1:30:01 all 64.17 0 4.72 26.31 0 4.81\n"
" 10/1/2017 1:40:01 all 47.54 0 4.23 19.44 0 28.79\n"
" 10/1/2017 1:50:01 all 44.59 0 3.68 17.47 0 34.27\n"
" 10/1/2017 2:00:01 all 49.16 0 4.22 13.47 0 33.15\n"
" 10/1/2017 2:10:01 all 41.98 0 3.95 16.47 0 37.59")
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