import re
regex = re.compile(r"([[:space:]]+|^)areaIntegrate\(down\) of grad\(T\)y[[:space:]]+", flags=re.MULTILINE)
test_str = ("\n"
"Time = 0\n\n"
"Reading fields:\n"
" volScalarField: grad(T)y\n\n"
"Executing functionObjects\n"
"surfaceFieldValue patchIntegrate(name=down,grad(T)y) write:\n"
" total faces = 4000\n"
" total area = 5.286456431623655e-06\n\n"
" areaIntegrate(down) of grad(T)y = -0.3799414476287353\n"
"Space-averaged Nusselt lambda = 5.34607670341618\n\n"
"Time = 0.45\n\n"
"Reading fields:\n"
" volScalarField: grad(T)y\n\n"
"Executing functionObjects\n"
"surfaceFieldValue patchIntegrate(name=down,grad(T)y) write:\n"
" areaIntegrate(down) of grad(T)y = -0.6680860499604798\n"
"Space-averaged Nusselt lambda = 5.34607670341618")
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