import re
regex = re.compile(r"^[A-Za-z]-.*$|^[A-Za-z]\s.*$")
test_str = ("CASE\n"
"regexp_replace (od_proposed,'^[A-Za-z]-.*$','^[A-Za-z]-\\d$')\n"
"regexp_replace (od,'^[A-Za-z]\\s.*$','^[A-Za-z]')\n\n\n\n"
"A-1 - AIRPLANE\n"
"A-2 - AIRPLANE\n"
"A-3 - AIRPLANE\n"
"A-4 - AIRPLANE\n"
"A-5 - AIRPLANE\n"
"B - BOARD ROOM\n"
"E - EMERGENCY: FIRST ROOM\n"
"F-1 - FIRST \n"
"F-2 - FIRST \n"
"H-1 - HOUSING\n"
"H-2 - HOUSING\n"
"H-3 - HOUSING\n"
"H-4 - HOUSING\n"
"I-1 - INITIAL\n"
"I-2 - INITIAL\n"
"I-3 - INITIAL\n"
"I-4 - INITIAL\n"
"M - MASTER\n"
"R-1 - REASON\n"
"R-2 - REASON\n"
"R-3 - REASON\n"
"S-1 - SHORTCUT: TO CAFE\n"
"S-2 - SHORTCUT: TO CAFE\n"
"U - UTILITY")
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