# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?i)(?m)(?<![a-z]|\.|\.\d)(?:\d{1,4})(?:[.,\s]\d{3})*(?:[.,]\d{2})(?!\%|\d|\.|\s\.|\scm|cm|pol|\spol)"
test_str = ("TICKET RESTAURANT DE PORTUGAL,\n"
"Infante Santo,\n"
"1350—177 Lisboa\n\n"
"S.A.\n\n"
"AV. 23 A/D\n\n"
"NIF e MAT.:\n"
"Cap.\n\n"
"500423849\n\n"
"Soc. 500.000 Euros\n\n"
"Z43\n\n"
"CDUCket\n\n"
";fensmoº\n\n"
"000370.19\n\n"
"FAS—SISTEMAS DE INFORMACAO LDA\n\n"
"TAGUS PARK\n\n"
"EDIFICIO QUALIDADE B2-1B\n\n"
"2740—120 PORTO SALVO\n\n"
" \n\n"
" \n\n"
" \n\n"
" \n\n"
" \n\n"
" \n\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"r\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"W\n"
"[\n\n"
" \n\n"
" \n\n"
" \n\n"
" \n\n"
" \n\n"
" \n\n"
"fwj+—Processado por programa certificado n.\n\n"
". ticket\n\n"
"SEFVIÇOS Delegação Nºrte\n\n"
"R. das Cardosas, 1495\n"
"4425 - 510 S.Pedro Fins Maia\n\n"
"Delegação Sul\n\n"
"Av. Infante Santo, 21 A\n\n"
"1350-177 Lisboa\n\n"
"Tel. 210 420 325 - Fax. 210 420 365\n\n"
"Hcket©tkketpt\n"
"Hcketpt\n\n"
"Pagamento por transferencia bancaria:\n"
"IBAN: PT50 0079 0000 64938339101 80\n\n"
"Delegação Centro\n\n"
"R. Álvaro Pires de Miranda,\n"
"Lt. 46 ,1.º Dto. A ' 2415-369 Leiria\n"
"Tel. 228 302 900 ' Fax. 228 302 904 Tel. 244 826 378 ' Fax. 244 823 689\n\n"
"2292/AT\n\n"
"W V/REQUISIÇÃO V/Nº CONTRIBUINTE Nº CLIE_NTE W DATA W\n"
"WI \"\"\" 777 һ\" ' W ORIGINAL DA ;\n"
"W WPT 502524588 EET 000370W 2017— 05- 03 FACTURA FET 17/1208\n"
"TICKET ENSINO fornecidos: , , W\n"
"% QUANHDADE ; VALORUNnAmo W VALORTOTAL\n"
"Emissão Ticket Ult. Ticket Cod. Produto « W\n"
"17002775 00015396 00015397 105.00/ET W 2W 105.00W 210.00\n"
"17002776 00015398 00015400 140.00/ET W 3; 140.00W 420.00\n"
"W W\n"
"W ? W\n"
"W * W\n"
"., W\n"
"W W W\n"
"W W\n"
"1 W W\n"
"W . í\n"
"W IVA ISENTO — Alineas &) e c) . 27 Artigo 9 W 5 W SUB-TOTAL * 630 . OOW (*)\n"
"L “2__ W W _“ “__mw ___-“ _, \"I\n"
"W wannn CWAEWKO 6.50% 23% TOTAL€\n"
"& Euros 630.00 40.95 .42 680.37\n"
"& Euros 630.00 40.95 9.42 680.37\n"
"288.890.234,23\n"
"SEISCENTOS E OITENTA EUROS E TRINTA E SETE CENTIMOS ****************\n"
"********************************************************************\n\n"
"SWIFT/BIC: BPNPPTPL\n\n"
"at\n\n"
"Delegação Madeira\n\n"
"Calçada de São Lourenço, nº 3, 2 C\n"
"9000-061 Funchal\n\n"
"Tel. 291 225 727 ' Fax. 291 230 694\n")
matches = re.finditer(regex, test_str)
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