import re
regex = re.compile(r"SPECGRID.*?\n([ \d]+)[\s\S]*?\/")
test_str = ("-- Generated [\n"
"-- Format : ECLIPSE keywords (grid geometry and properties) (ASCII)\n"
"-- Exported by : Petrel 2014.4 (64-bit) Schlumberger\n"
"-- User name : apitchford\n"
"-- Date : Friday, April 29 2016 15:20:42\n"
"-- Project : Glenloth19April2016.pet\n"
"-- Grid : Tartan Wide 3D grid 150 prop\n"
"-- Generated ]\n\n"
"PINCH -- Generated : Petrel\n"
" /\n\n"
"MAPUNITS -- Generated : Petrel\n"
" METRES /\n\n"
"MAPAXES -- Generated : Petrel\n"
" 156653.33 7788633.76 156653.33 7789633.76 157653.33 7789633.76 /\n\n"
"GRIDUNIT -- Generated : Petrel\n"
" METRES /\n\n"
"SPECGRID -- Generated : Petrel\n"
" 54 166 127 1 F /\n\n"
"COORDSYS -- Generated : Petrel\n"
" 1 127 /")
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