import re
regex = re.compile(r"^(?!(d|b y|toy);([^;\r\n]*);([^;\r\n]*)).*\R", flags=re.MULTILINE)
test_str = ("\n"
"a;; z\n"
"toy;d;hh \n"
"z;\n"
"d;23\n"
";;io;\n"
"b y;b;12\n\n"
"a;b;bb;;;34\n"
" ")
subst = "$3"
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