import re
regex = re.compile(r"SPECGRID([\s\S]*?)\/")
test_str = ("MAPAXES -- Generated : Petrel\n"
" 159589.61 7782837.94 159589.61 7783837.94 160589.61 7783837.94 /\n\n"
"GRIDUNIT -- Generated : Petrel\n"
" METRES /\n\n"
"SPECGRID -- Generated : Petrel\n"
" 3 26 120 1 F /\n\n"
"COORDSYS -- Generated : Petrel\n"
" 1 120 /\n")
match = regex.search(test_str)
if match:
print(f"Match 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