# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?#Header Cielo 03)^0([\d]{10})([\d]{8})([\d]{8})([\d]{8})([\d]{7})([CIELO]{5})([03]{2})([I|P]{1})([\w\s]{20})([001]{3})([\w\s]{177})$|(?#RO Venda Cielo 03)^1([\d]{10})([\d]{7})([\d\s]{2})([a,\/,\s]{1})([\d\s]{2})(01)([\d]{6})([\d]{6})([\d]{6})([\D\d]{14})([\D\d]{14})([\D\d]{14})([\D\d]{14})([\d]{4})([\d]{5})([\d\s]{14})(00)([\d]{6})([\d]{2})([\d]{6})([\sRA]{1})([\d]{6})([\s]{2})([\d]{13})([\sCA]{1})([\d\S]{9})([\D\d]{14})([\d]{3})([\d]{22})([\d]{4})([\d]{5})([\d]{4})([\d\w\s]{2})([\w\s]{8})([\d]{3})([\s]{15})$|(?#CV Cielo 03)^2([\d]{10})([\d]{7})([\d\D]{19})([\d]{8})([\D\d]{14})([\d]{2})([\d]{2})([\w\s]{3})([\w\s]{6})([\d\s]{20})([\d]{6})([\d]{13})([\d]{2})([\d]{13})([\d\s]{13})([\d]{9})([0-2]{4})([\w\s]{8})([\s|TX|VE]{2})([\d\s]{20})([\d]{6})([\d]{29})([\w\s]{1})([\s]{32})$|(?#RO Pago Cielo 03)^1([\d]{10})([\d]{7})([\d\s]{2})([a,\/,\s]{1})([\d\s]{2})(01)([\d]{6})([\d]{6})([\d]{6})([\D\d]{14})([\D\d]{14})([\D\d]{14})([\D\d]{14})([\d]{4})([\d]{5})([\d\s]{14})(01)([\d]{6})([\d]{2})([\d]{6})([\sRA]{1})([\d]{6})([\s\d]{2})([\d]{13})([\sCA]{1})([\d\S]{9})([\D\d]{14})([\d]{3})([\d]{22})([\d]{4})([\d]{5})([\d]{4})([\d\w\s]{2})([\w\s]{8})([\d]{3})([\s]{15})$|(?#RO Serviço Cielo 03 Ajuste e Serviços)^1([\d]{10})([\d]{7})([\d\s]{2})([a,\/,\s]{1})([\d\s]{2})(02|03|04|05)([\d]{6})([\d]{6})([\d]{6})([\D\d]{14})([\D\d]{14})([\D\d]{14})([\D\d]{14})([\d]{4})([\d]{5})([\d\s]{14})(00|01|02|03)([\d]{6})([\d]{2})([\d]{6})([\sRA]{1})([\d]{6})([\s\d]{2})([\d]{13})([\sCA]{1})([\d\S]{9})([\D\d]{14})([\d]{3})([\d]{22})([\d]{4})([\d]{5})([\d]{4})([\d\w\s]{2})([\w\s]{8})([\d]{3})([\s]{15})$|(?#RO Enviado Banco Cielo 03)^1([\d]{10})([\d]{7})([\d\s]{2})([a,\/,\s]{1})([\d\s]{2})(01)([\d]{6})([\d]{6})([\d]{6})([\D\d]{14})([\D\d]{14})([\D\d]{14})([\D\d]{14})([\d]{4})([\d]{5})([\d\s]{14})(02)([\d]{6})([\d]{2})([\d]{6})([\sRA]{1})([\d]{6})([\s\d]{2})([\d]{13})([\sCA]{1})([\d\S]{9})([\D\d]{14})([\d]{3})([\d]{22})([\d]{4})([\d]{5})([\d]{4})([\d\w\s]{2})([\w\s]{8})([\d]{3})([\s]{15})$|(?#RO A CONFIRMAR Cielo 03)^1([\d]{10})([\d]{7})([\d\s]{2})([a,\/,\s]{1})([\d\s]{2})(01)([\d]{6})([\d]{6})([\d]{6})([\D\d]{14})([\D\d]{14})([\D\d]{14})([\D\d]{14})([\d]{4})([\d]{5})([\d\s]{14})(03)([\d]{6})([\d]{2})([\d]{6})([\sRA]{1})([\d]{6})([\s\d]{2})([\d]{13})([\sCA]{1})([\d\S]{9})([\D\d]{14})([\d]{3})([\d]{22})([\d]{4})([\d]{5})([\d]{4})([\d\w\s]{2})([\w\s]{8})([\d]{3})([\s]{15})$|(?#Trailer Cielo 03)^9\d{11}.*$"
test_str = ("010072994502016122720161227201612270006712CIELO03PEC2354 001 \n"
"110072994505161226 01161226170125000000+0000000004525-0000000000226+0000000000000+0000000004299023700974000002239P 0000000146000000 161226 0000000000000 000000000+0000000000000007163610370009502000000005000000000000242183323046 \n"
"210072994505161226506700******601300020161226+00000000045250000 852956 26011900000000000001600000000000000000000000000000000000000142183323 18285816361037000950200000000001000 \n"
"110072994505161226 01161226161227000000+0000000002000-0000000000036+0000000000000+0000000001964010400461000030090036750000000171000000 161226 0000000000000 000000000+00000000000000071636160900195540000000018200000000001WR023012071 \n"
"210072994505161226627780******473200020161226+00000000020000000 721689 777266000000000000016000000000000000000000000000000000000001WR023012 18223616361609001955400000000001000 \n"
"110072994505161226 01161226161227000000+0000000013218-0000000000240+0000000000000+0000000012978010400461000030090036750000000571000000 161226 0000000000000 000000000+0000000000000007163615060072658000000001820000000000242183323071 \n"
"210072994505161226627780******573300020161226+00000000021700000 114576 26000400000000000001600000000000000000000000000000000000000142183323 08263816361506007265800000000001000 \n"
"210072994505161226627780******074400020161226+00000000016520000 203138 26002100000000000001600000000000000000000000000000000000000142183323 09552916361506007265800000000002000 \n"
"210072994505161226627780******016500020161226+00000000034370000 475524 26003500000000000001600000000000000000000000000000000000000142183323 11051216361506007265800000000003000 \n"
"210072994505161226627780******978100020161226+00000000024240000 494289 26003600000000000001600000000000000000000000000000000000000142183323 11060716361506007265800000000004000 \n"
"210072994505161226627780******521100020161226+00000000035350000 242001 26004900000000000001600000000000000000000000000000000000000142183323 11411916361506007265800000000005000 \n"
"110072994505161226 01161226161227000000+0000000001515-0000000000028+0000000000000+0000000001487010400461000030090036750000000171000000 161226 0000000000000 000000000+0000000000000007163615070073805000000001820000000000242183323071 \n"
"210072994505161226506731******910600020161226+00000000015150000 383179 26006200000000000001600000000000000000000000000000000000000142183323 14325916361507007380500000000001000 \n"
"110072994505161226 01161226161227000000+0000000023435-0000000000426+0000000000000+0000000023009010400461000030090036750000000971000000 161226 0000000000000 000000000+0000000000000007163615080063547000000001820000000000242183323071 \n"
"210072994505161226627780******713600020161226+00000000019840000 529099 26007300000000000001600000000000000000000000000000000000000142183323 15302716361508006354700000000001000 \n"
"210072994505161226627780******259900020161226+00000000012900000 761140 26008900000000000001600000000000000000000000000000000000000142183323 17281616361508006354700000000002000 \n"
"210072994505161226627780******573300020161226+00000000036000000 170156 26009700000000000001600000000000000000000000000000000000000142183323 17502116361508006354700000000003000 \n"
"210072994505161226506731******320100020161226+00000000044090000 385284 26010400000000000001600000000000000000000000000000000000000142183323 18062416361508006354700000000004000 \n"
"210072994505161226627780******038400020161226+00000000007890000 469596 26010500000000000001600000000000000000000000000000000000000142183323 18072816361508006354700000000005000 \n"
"210072994505161226627780******473200020161226+00000000016410000 710137 26011300000000000001600000000000000000000000000000000000000142183323 18215316361508006354700000000006000 \n"
"210072994505161226627780******970100020161226+00000000028110000 722260 26011400000000000001600000000000000000000000000000000000000142183323 18223916361508006354700000000007000 \n"
"210072994505161226627780******374300020161226+00000000033050000 103822 26012700000000000001600000000000000000000000000000000000000142183323 18471816361508006354700000000008000 \n"
"210072994505161226627780******035100020161226+00000000036060000 206415 26013200000000000001600000000000000000000000000000000000000142183323 18541516361508006354700000000009000 \n"
"110072994505161226 01161226161227000000+0000000019307-0000000000350+0000000000000+0000000018957010400461000030090036750000000671000000 161226 0000000000000 000000000+0000000000000007163615090044288000000001820000000000242183323071 \n"
"210072994505161226627780******938900020161226+00000000038580000 241875 26013300000000000001600000000000000000000000000000000000000142183323 18564416361509004428800000000001000 \n"
"210072994505161226627780******276500020161226+00000000036360000 404956 26014200000000000001600000000000000000000000000000000000000142183323 19083416361509004428800000000002000 \n"
"210072994505161226627780******053300020161226+00000000052870000 562554 26015000000000000001600000000000000000000000000000000000000142183323 19202816361509004428800000000003000 \n"
"210072994505161226627780******400200020161226+00000000018340000 761322 26016100000000000001600000000000000000000000000000000000000142183323 19363216361509004428800000000004000 \n"
"210072994505161226509091******810000020161226+00000000041850000 386308 26016900000000000001600000000000000000000000000000000000000142183323 19500816361509004428800000000005000 \n"
"210072994505161226506727******110300020161226+00000000005070000 386367 26017500000000000001600000000000000000000000000000000000000142183323 19560716361509004428800000000006000 \n"
"900000000029 \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