import re
regex = re.compile(r"^([A-zÀ-ÿ]{2,}([.-])?)+( ?(([A-zÀ-ÿ]){2,}([.-])?))* (([A-zÀ-ÿ]){2,}([.-])?)+$", flags=re.MULTILINE)
test_str = ("xfbhc-xbfdfg fdhfdhdrhhdffh grgfdbdf ñÁ-ñÁ\n\n"
"dfgffsdfd-dfggsgsg sr. sfefsg\n\n"
"Roberto Jr.\n\n"
"Carlos-pablos Petrosyan jr.\n\n"
"carlos-pablos Petrosyan jr.\n\n"
"Rodrigo Jr. Ahora\n\n"
"Gabriel Ira rodrigez. jr.\n\n"
"Gabriel Ira rodr-igez. jr.\n\n"
"Ira Gabriel rodb nman-jnir ngor\n\n"
"Ira gabriel rodb nman-jnir. ngo\n\n"
"Gabriel Jr. Ira rodr-igez jr-\n\n"
"-------------------------------------------------------------\n\n"
"fdghdf dggdg dgdghdh dfff dgggddggdgh\n\n"
"Gabriel Ira rodr-igez. jr. \n\n"
"Gabriel Jr.. Ira rodr-igez. jr.\n\n"
"Gabriel.. Jr. Ira rodr-igez. jr.\n\n"
"rodrigo jr.. ahora\n\n"
"knlknllk k fgjnfn\n\n"
"hgh\n\n"
"hgghrhgfnf\n\n"
" jhdsbdhfbj\n\n"
"dfvdfvf sdvds ")
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