import re
regex = re.compile(r"(?:^:([A-Za-z0-9]+):|(?!^)\G)\n+([A-Za-z/.-]+)", flags=re.MULTILINE)
test_str = (":6585d0f0ba88767ac3b590f719596d864d73e9c1:\n\n"
"harmonicbalance/src/harmonicbalance/HarmonicBalanceFlowModel.cpp\n"
"harmonicbalance/src/harmonicbalance/HbFlutterModel.cpp\n"
":8302994b565553c83a048b8905ae597349d99627:\n\n"
"emp/src/emp/PhasePairSingleParticleReynoldsNumber.h\n"
"emp/src/emp/TomiyamaDragCoefficientMethod.cpp\n"
":9da194f17ec08bb20ad1be8df68b78ca137ab18a:\n\n"
"combustion/src/combustion/ReactingSpeciesTransportBasedModel.cpp\n"
"combustion/src/complexchemistry/TurbulentFlameClosure.cpp\n"
":6a59f0be1e347a65e525e58742bb304639ea9bc4:\n\n"
"meshing/src/meshing/SurfaceMeshManipulation.cpp\n"
"physics/src/discretization/FvIndirectRegionInterfaceManager.cpp\n"
"physics/src/discretization/FvIndirectRegionInterfaceManager.h\n"
"physics/src/discretization/FvRepresentation.cpp\n"
"physics/src/discretization/FvRepresentation.h\n"
":64b7f6d36b11b6cd94c20cad53463b7deef8c85a:\n\n"
"resourceclient/src/resourceclient/ResourcePool.cpp\n"
"resourceclient/src/resourceclient/ResourcePool.h\n"
"resourceclient/src/resourceclient/RestClient.cpp\n"
"resourceclient/src/resourceclient/RestClient.h\n"
"resourceclient/src/resourceclient/test/ResourcePoolTest.cpp")
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