# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^([A-Z]+):\s+([A-Z]+)\s*(.*)$"
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")
matches = re.search(regex, test_str, re.MULTILINE)
if matches:
print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group()))
for groupNum in range(0, len(matches.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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