import re
regex = re.compile(r"(var )?(\"[^\"\r\n\t]+\"|[a-z0-9\_]+)\s?\:\s([a-z\[\]0-9]+)\s?(\'[^\'\;]+\'|\"[^\"\;]+\"|of [^\"\;]+|[^\"\s\;]+|)( temporary)?(?:\;|\))", flags=re.MULTILINE | re.IGNORECASE)
test_str = ("local procedure OnBeforeGetNoSeriesCode(var SalesHeader: Record \"Sales Header\"; SalesSetup: Record \"Sales & Receivables Setup\"; var NoSeriesCode: Code[20]; var IsHandled: Boolean)\n\n"
"local procedure OnBeforeInitRecord(var SalesHeader: Record \"Sales Header\"; var IsHandled: Boolean; xSalesHeader: Record \"Sales Header\")\n\n"
"local procedure OnBeforeIsCreditDocType(SalesHeader: Record \"Sales Header\"; var CreditDocType: Boolean)\n\n"
"procedure RecreateSalesLines(ChangedFieldName: Text[100])\n\n"
"local procedure GetSalesSetup()\n\n"
" procedure PopulateItemAttributeValueSelection(var TempItemAttributeValue: Record \"Item Attribute Value\" temporary;var TestBool: Boolean)")
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