import re
regex = re.compile(r"^([A-Z]+):\s+([A-Z]+)\s*(.*)$", flags=re.MULTILINE)
test_str = ("CLRFCB:\n"
"FCB: EQU 5CH\n"
"SYSTEM: EQU 5\n"
"OPEN: EQU 15\n"
"CLOSE: EQU 16\n"
"SETDMA: EQU 26\n"
"CREATE: EQU 22\n"
"DELETE: EQU 19\n"
"READ: EQU 20\n"
"WRITE: EQU 21\n"
"PRNBUF: EQU 9\n"
" MOV SP,STACK\n"
" MOV DX,HEADER\n"
" MOV CL,9 \n"
" CALL SYSTEM\n"
" MOV BX,FCB+12\n"
" XOR AL,AL\n"
" MOV CH,4 \n"
"CLRFCB:\n"
" MOV [BX],AL")
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