import re
regex = re.compile(r"([a-zA-Z0-9]=)|(\n\s*\{)|(\(\s)|(\s\))|(\s,)|(\n\s*\{)|(\t)|(\)\{)|(.{81,})|([a-zA-Z0-9][&|\+\-\*\/%]+[a-zA-Z0-9])|(class [a-z])|(class .*_)|( ;)|(==[a-zA-Z0-9])|([a-zA-Z0-9].=[a-zA-Z0-9])")
test_str = ("Any \"matches\" here indicate a possible style error.\n\n"
"Please note that this is not 100% perfect (although we tried our best!)\n\n"
"This may not catch everything, and may incorrectly catch others.\n"
"If you believe there is an incorrect match, let us know\n"
"on the form when you submit your document.\n\n"
"Please ignore any matches within your comments or string literals.\n"
"(i.e. you can break \"coding style\" in a comment)\n\n"
"Thank you!")
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