import re
regex = re.compile((r"(?P<master>([a-zA-Z0-9_]*\.|))Sequence\((\s*|)((!?(?P=master))([a-zA-Z0-9_]*)\(([a-zA-Z0-9_\(\)\,=>\{\}\s]*)\)(\,\s*|\,\n|\,|()))*(\n|)\)\;\n"), flags=re.MULTILINE)
test_str = ("this.Sequence(this.Delay(1));\n\n"
"this.Sequence(this.Delay(1),this.Delay(1));\n\n"
"other.Sequence(this.Delay(1)); other.Sequence(this.Delay(1));\n"
"other.Sequence(other.Delay(1));\n"
"this.Sequence(other.Delay(1));\n\n"
"Sequence(\n"
" this.Delay(1)\n"
");\n\n"
"Sequence(\n"
" this.Delay(1),\n"
" this.Delay(1),\n"
" this.Value(1, 0, 1, (v)=>{}),\n"
" this.Value(1,0,1, delegate(v){}),\n"
");\n\n\n"
"//coment\n"
"a = 1;\n"
"this.GetPosition();")
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