import re
regex = re.compile(r"(?<=CBEAM 241699|CBEAM 241711).*?(0\.2750).*?(0\.2750)", flags=re.DOTALL)
test_str = ("CBEAM 241678 245002 240528 240628 10. 0. 10. GOO\n"
" 0. 0.2750 0. 0. 0.2750 0.\n"
"CBEAM 241697 245002 240230 240330 10. 0. 10. GOO\n"
" 0. 0.2750 0. 0. 0.2750 0.\n"
"CBEAM 241698 245002 240330 240430 10. 0. 10. GOO\n"
" 0. 0.2750 0. 0. 0.2750 0.\n"
"CBEAM 241699 245002 240430 240530 10. 0. 10. GOO\n"
" 0. 0.2750 0. 0. 0.2750 0.\n"
"CBEAM 241700 245002 240530 240630 10. 0. 10. GOO\n"
" 0. 0.2750 0. 0. 0.2750 0.\n"
"CBEAM 241708 245002 240231 240331 10. 0. 10. GOO\n"
" 0. 0.2750 0. 0. 0.2750 0.\n"
"CBEAM 241709 245002 240331 240431 10. 0. 10. GOO\n"
" 0. 0.2750 0. 0. 0.2750 0.\n"
"CBEAM 241710 245002 240431 240531 10. 0. 10. GOO\n"
" 0. 0.2750 0. 0. 0.2750 0.\n"
"CBEAM 241711 245002 240531 240631 10. 0. 10. GOO\n"
" 0. 0.2750 0. 0. 0.2750 0.")
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