import re
regex = re.compile(r"^[\s+-]?[^\s]+\s([^\s\n]+).*$", flags=re.MULTILINE)
test_str = (" +883620946918182db5a277fc5e328fee3030ef79 src/dobot_cr_driver (8836209)\n"
"-8fc5c05835a246d7cb46952f748efec11fbf0075 src/onrobot_driver\n"
" b5704131f0e2964e4d051d5e6f6560917c2a1969 src/ros_camera\n"
" 1ffdd69181389b14b7d6342f0c5bad3b45c5e32f src/ur_meta (1.1.5-315-g1ffdd69)\n"
" ec2beb65afd6be5373d1e21a86dd42a07e25b447 src/ur_official_driver (v2.0.0-4-gec2beb6)\n"
" 883620946918182db5a277fc5e328fee3030ef79 src/dobot_cr_driver (8836209)\n"
" 8fc5c05835a246d7cb46952f748efec11fbf0075 src/onrobot_driver (8fc5c05)\n"
" b5704131f0e2964e4d051d5e6f6560917c2a1969 src/ros_camera (heads/develop)\n"
" 1ffdd69181389b14b7d6342f0c5bad3b45c5e32f src/ur_meta (1.1.5-315-g1ffdd69)\n"
" ec2beb65afd6be5373d1e21a86dd42a07e25b447 src/ur_official_driver (v2.0.0-4-gec2beb6)")
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