import re
regex = re.compile(r"^([cC]\/|[cC]alle|[aA]v\/|[aA]venida|[pP]laza\/|[pP]laza)\s([A-z ]{0,})\,\s\d+$", flags=re.MULTILINE)
test_str = ("calle prueba, 2\n"
"calle de la prueba, 5\n"
"Avenida de la prueba, 5\n"
"Plaza de la prueba, 5\n"
"Calle Higuereta, 4, 7º B\n"
"Calle Escritor Conde Zamora s/n\n"
"Avenida Ciudad de Aranjuez 18\n"
"Avenida Pintor Sorolla 125 4ºG\n"
"Polígono Industrial Aranguren 6\n"
"Calle Gremi Passamaners 24 2º\n"
"Avenida Manuel Rodriguez Ayuso, 170\n"
"Calle Illa de Buda 55\n"
"C/ Walia, 21 \n"
"C/Alfonso Pesquera, 6")
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