import re
regex = re.compile(r"^\s*(?:[a-z]{2,}\.\s*)?(?:[a-zñ]{2,}\s*[a-zñ ]*,\s*[a-zñ]+\s*[a-zñ ]*(?:[a-zñ]\.?\s*){0,3}|[a-zñ]+\s*[a-zñ ]*\s+(?:[a-zñ]\.?\s*){0,3}[a-zñ]{2,}\s*[a-zñ ]*)\s*(?:[a-zñ., ])*$", flags=re.IGNORECASE | re.MULTILINE)
test_str = ("1\n"
"Christopher Quimpo\n"
"Christopher P. Quimpo\n"
"Engr. Christopher P. Quimpo\n"
"Z G. Gono\n"
"Qu, C\n"
"Engr. Q, C\n"
"Christopher Quimpo\n"
"1\n"
"Christopher\n"
"1\n"
"Q C\n"
"1")
subst = "col.Add \"$1\""
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