# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"([\w\s]+)\(dir\. ([\w\s]+) \| ([\w\s]+) \| (\d{4}) \| (\d+ min)\)(.*?)((?:\d{1,2} de [a-z]+ \| [\w\-]+ \| \d{1,2}[hH]\s*)+)"
test_str = ("REDENÇÃO\n"
"(dir. Roberto Pires | Brasil | 1958 | 61 min)\n"
"Newton e Raul, dois jovens rapazes catadores de coco em um bairro pobre de Salvador, dão abrigo a um homem estranho e peculiar que chegou no meio da noite com o carro quebrado. No dia seguinte, os dois saem de casa e deixam o estranho trancado em casa; quando a noiva de Newton chega à casa no período da noite, o estranho tenta atacá-la.\n"
"21 de agosto | segunda-feira | 16h\n"
"25 de agosto | sexta-feira | 19h\n"
"30 de agosto | quarta-feira | 16h")
matches = re.finditer(regex, test_str, re.MULTILINE | re.DOTALL)
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