# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^(Em\s)?\d{1,2}\sde\s\w+\sde\s\d{4}\s\d{1,2}:\d{1,2}([^@]+@\w+\.\w+\.\w+|,\s\sescreveu\:)?"
test_str = ("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\n"
"5 de Abril de 2018 10:50, atendimento@teste.com.br (mailto:atendimento@teste.com.br) escreveu:teste\n\n"
"Em 5 de Abril de 2018 10:30, atendimento@teste.com.br (mailto:atendimento@teste.com.br) escreveu:resposta atendimento\n\n"
"-----------------------------------------------------------\n\n"
"Olá, como vai?\n\n"
"10 de abril de 2018 09:49\n\n"
"10 de abril de 2018 09:49, escreveu:\n\n"
"Em 10 de abril de 2018 09:49\n\n"
"Em 10 de abril de 2018 09:49, escreveu:\n\n"
"> Resposta atendimento\n"
">\n"
">\n"
"> 10 de Abril de 2018 09:48, \"erick zanetti\" > escreveu:\n"
">\n"
">\n"
"> Olá, erick,\n"
"> A data de entrega do seu trabalho Lista Vetores\n"
"> é\n"
"> amanhã. Você deseja entregá-lo?\n"
">\n"
">\n"
"> Lista Vetores\n"
"> Prazo: 7 de abr\n"
"> ABRIR\n"
">\n"
"> Se você não quiser receber e-mails do Sala de aula, cancele sua inscrição\n"
"> .\n"
">\n"
">\n"
">")
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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