import re
regex = re.compile(r"([2-6]ª[-feira]{0,})|^(segunda|terça|quarta|quinta|sexta)\b[-feira]{0,}", flags=re.MULTILINE)
test_str = ("2ª\n"
"3ª\n"
"4ª\n"
"5ª\n"
"6ª\n"
"2ª-feira\n"
"3ª-feira\n"
"4ª-feira\n"
"5ª-feira\n"
"6ª-feira\n"
"segunda\n"
"terça\n"
"quarta\n"
"quinta\n"
"sexta\n"
"segunda-feira\n"
"terça-feira\n"
"quarta-feira\n"
"quinta-feira\n"
"sexta-feira\n\n"
"____________Não_\n"
"oitava-feira\n"
"sexta-\n"
"sextafeira\n"
"-feira\n"
"feira\n"
"22ª\n"
"1ª\n"
"7ª\n"
"ª\n"
"2-feira\n"
"aquartado\n"
"sextavado")
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