import re
regex = re.compile(r"""
^
(?:
.
(?=
.*+\n
(\1?+.)
.*+\n
(\2?+.)
.*+\n
(\3?+.)
)
)*?
...A.*+\n
\1?+
..A.*+\n
\2?+
.A.*+\n
\3?+
A
""", flags=re.MULTILINE | re.VERBOSE)
test_str = ("0000000\n"
"0000000\n"
"000A000\n"
"00AB000\n"
"AAAB000\n"
"ABBB000")
subst = ""
result = regex.sub(subst, test_str)
if result:
print(result)
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