import re
regex = re.compile(r"EGA-(?:(?!New=).)+(New=[:\d\/ ]+)")
test_str = ("structure(list(flight_history_id = c(280604281L, 280316415L, \n"
"280315758L, 280316495L, 280303866L, 280303866L, 280271465L, 280271465L, \n"
"280271465L, 280271465L), date_time_recorded = structure(c(10L, \n"
"4L, 3L, 2L, 7L, 1L, 9L, 8L, 6L, 5L), .Label = c(\"2012-11-12 05:50:23.547-08\", \n"
"\"2012-11-12 15:38:10.099-08\", \"2012-11-12 16:10:06.968-08\", \"2012-11-12 17:25:08.814-08\", \n"
"\"2012-11-12 17:58:14.268-08\", \"2012-11-13 05:16:41.01-08\", \"2012-11-13 06:51:45.831-08\", \n"
"\"2012-11-13 07:38:19.593-08\", \"2012-11-13 07:54:22.588-08\", \"2012-11-13 17:55:58.673-08\"\n"
"), class = \"factor\"), event = structure(c(1L, 2L, 2L, 2L, 2L, \n"
"2L, 2L, 2L, 2L, 2L), .Label = c(\"Arrival Estimation\", \"Time Adjustment\"\n"
"), class = \"factor\"), data_updated = structure(c(3L, 8L, 7L, \n"
"4L, 2L, 5L, 1L, 10L, 9L, 6L), .Label = c(\"AGD- New=11/13/12 10:22, EGA- Old=11/13/12 11:20 New=11/13/12 11:09\", \n"
"\"AGD- Old=11/13/12 07:40 New=11/13/12 07:38, EGA- Old=11/13/12 10:25 New=11/13/12 10:18\", \n"
"\"EGA- Based on Distance and Airspeed\", \"EGD- New=11/13/12 06:35, DGATE- New=A1, EGA- New=11/13/12 07:15\", \n"
"\"EGD- New=11/13/12 07:45, DGATE- New=11, EGA- New=11/13/12 10:25, AGATE- New=A1\", \n"
"\"EGD- New=11/13/12 08:55, EGA- New=11/13/12 09:45, AGATE- New=A1\", \n"
"\"EGD- New=11/13/12 19:05, DGATE- New=A7, EGA- New=11/13/12 20:50, AGATE- New=C5\", \n"
"\"EGD- New=11/13/12 20:20, DGATE- New=A1, EGA- New=11/13/12 21:00\", \n"
"\"EGD- Old=11/13/12 08:55 New=11/13/12 10:05, EGA- Old=11/13/12 09:45 New=11/13/12 10:55\", \n"
"\"EGD- Old=11/13/12 10:05 New=11/13/12 10:30, EGA- Old=11/13/12 10:55 New=11/13/12 11:20\"\n"
"), class = \"factor\")), .Names = c(\"flight_history_id\", \"date_time_recorded\", \n"
"\"event\", \"data_updated\"), row.names = c(862L, 5514L, 5527L, 5539L, \n"
"5545L, 5558L, 5564L, 5566L, 5570L, 5572L), class = \"data.frame\")")
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