# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"\d{44}"
test_str = (" Found 55 barcodes:\n"
" 1) I2of5, Confidence: 1,00, Page 1, Rectangle: [231; 2494; 1271; 1]\n"
" Value: 89620000002429000411110202208291001225388559\n"
" 2) I2of5, Confidence: 0,50, Page 2, Rectangle: [606; 645; 219; 1]\n"
" Value: 3505\n"
" 3) I2of5, Confidence: 1,00, Page 2, Rectangle: [266; 2478; 1270; 1]\n"
" Value: 89650000002409000411110202207291001225323761\n"
" 4) I2of5, Confidence: 0,50, Page 3, Rectangle: [2058; 1985; 192; 1]\n"
" Value: 5862\n"
" 5) I2of5, Confidence: 0,50, Page 3, Rectangle: [260; 2485; 1270; 1]\n"
" Value: 89680000002429000411110202208291001225388504\n"
" 6) I2of5, Confidence: 0,50, Page 4, Rectangle: [1544; 1229; 280; 1]\n"
" Value: 0316\n"
" 7) I2of5, Confidence: 0,50, Page 4, Rectangle: [279; 2487; 1271; 1]\n"
" Value: 89620000002429000411110202208291001225388502\n"
" 8) I2of5, Confidence: 1,00, Page 5, Rectangle: [258; 2491; 1271; 1]\n"
" Value: 89610000002429000411110202208291001225388499\n"
" 9) I2of5, Confidence: 0,50, Page 6, Rectangle: [237; 2601; 1271; 1]\n"
" Value: 89660000002553300411110202208291001225310933\n"
" 10) I2of5, Confidence: 0,50, Page 7, Rectangle: [575; 1557; 220; 1]\n"
" Value: 1555\n"
" 11) I2of5, Confidence: 0,50, Page 7, Rectangle: [239; 2508; 1270; 1]\n"
" Value: 89670000002429000411110202208291001225388552\n"
" 12) I2of5, Confidence: 0,50, Page 8, Rectangle: [254; 2413; 1270; 1]\n"
" Value: 89650000002429000411110202208291001225388497\n"
" 13) I2of5, Confidence: 0,50, Page 9, Rectangle: [584; 1563; 226; 1]\n"
" Value: 1545\n"
" 14) I2of5, Confidence: 0,50, Page 9, Rectangle: [237; 2515; 1271; 1]\n"
" Value: 89610000002429000411110202208291001225388480\n"
" 15) I2of5, Confidence: 0,50, Page 10, Rectangle: [575; 655; 228; 1]\n"
" Value: 2555\n"
" 16) I2of5, Confidence: 0,50, Page 10, Rectangle: [578; 1553; 226; 1]\n"
" Value: 1555\n"
" 17) I2of5, Confidence: 1,00, Page 10, Rectangle: [236; 2497; 1270; 1]\n"
" Value: 89620000002429000411110202208291001225388540\n"
" 18) I2of5, Confidence: 0,50, Page 11, Rectangle: [231; 2475; 1266; 1]\n"
" Value: 89680000003888000411110202208191001225366638\n"
" 19) I2of5, Confidence: 0,50, Page 12, Rectangle: [231; 2473; 1266; 1]\n"
" Value: 89680000003888000411110202208191001225366662\n"
" 20) I2of5, Confidence: 0,50, Page 13, Rectangle: [1517; 364; 280; 1]\n"
" Value: 0316\n"
" 21) I2of5, Confidence: 0,50, Page 13, Rectangle: [619; 614; 319; 1]\n"
" Value: 797113\n"
" 22) I2of5, Confidence: 0,50, Page 13, Rectangle: [264; 2539; 1265; 1]\n"
" Value: 89600000002429000411110202208261001225388255\n"
" 23) I2of5, Confidence: 1,00, Page 14, Rectangle: [228; 2523; 641; 1]\n"
" Value: 8968000000281200041111\n"
" 24) I2of5, Confidence: 1,00, Page 14, Rectangle: [228; 2526; 815; 1]\n"
" Value: 8968000000281200041111020220\n"
" 25) I2of5, Confidence: 0,50, Page 14, Rectangle: [228; 2533; 1214; 1]\n"
" Value: 896800000028120004111102022082610012253881\n"
" 26) I2of5, Confidence: 0,50, Page 14, Rectangle: [228; 2535; 1263; 1]\n"
" Value: 89680000002812000411110202208261001225388113\n"
" 27) I2of5, Confidence: 0,50, Page 15, Rectangle: [275; 2539; 1264; 1]\n"
" Value: 89660000002429000411110202208261001225388115\n"
" 28) I2of5, Confidence: 1,00, Page 16, Rectangle: [249; 2454; 1263; 1]\n"
" Value: 89610000002429000411110202208291001225388512\n"
" 29) I2of5, Confidence: 0,50, Page 17, Rectangle: [581; 679; 228; 1]\n"
" Value: 2505\n"
" 30) I2of5, Confidence: 1,00, Page 17, Rectangle: [581; 1548; 209; 1]\n"
" Value: 3759\n"
" 31) I2of5, Confidence: 0,50, Page 17, Rectangle: [240; 2622; 1263; 1]\n"
" Value: 89600000000971600411110202208291001225388554\n"
" 32) I2of5, Confidence: 0,50, Page 18, Rectangle: [1502; 1192; 279; 1]\n"
" Value: 0316\n"
" 33) I2of5, Confidence: 1,00, Page 18, Rectangle: [243; 2376; 1263; 1]\n"
" Value: 89610000003037000411110202208291001225388574\n"
" 34) I2of5, Confidence: 0,50, Page 19, Rectangle: [1484; 1229; 279; 1]\n"
" Value: 0316\n"
" 35) I2of5, Confidence: 0,50, Page 19, Rectangle: [224; 2454; 1263; 1]\n"
" Value: 89690000002429000411110202208291001225388773\n"
" 36) I2of5, Confidence: 0,50, Page 20, Rectangle: [276; 2536; 1262; 1]\n"
" Value: 89650000002429000411110202208291001225388812\n"
" 37) I2of5, Confidence: 0,50, Page 21, Rectangle: [590; 1578; 225; 1]\n"
" Value: 2505\n"
" 38) I2of5, Confidence: 0,50, Page 21, Rectangle: [242; 2566; 1263; 1]\n"
" Value: 89600000002510000411110202208291001225388894\n"
" 39) I2of5, Confidence: 0,50, Page 22, Rectangle: [576; 1500; 228; 1]\n"
" Value: 1505\n"
" 40) I2of5, Confidence: 0,50, Page 22, Rectangle: [234; 2451; 1263; 1]\n"
" Value: 89620000002429000411110202208291001225388936\n"
" 41) I2of5, Confidence: 1,00, Page 23, Rectangle: [224; 2457; 1263; 1]\n"
" Value: 89610000002892000411110202208291001225388743\n"
" 42) I2of5, Confidence: 0,50, Page 24, Rectangle: [575; 670; 225; 1]\n"
" Value: 3505\n"
" 43) I2of5, Confidence: 0,50, Page 24, Rectangle: [573; 1578; 225; 1]\n"
" Value: 3595\n"
" 44) I2of5, Confidence: 0,50, Page 24, Rectangle: [230; 2533; 1263; 1]\n"
" Value: 89630000002579000411110202208291001225388890\n"
" 45) I2of5, Confidence: 0,50, Page 25, Rectangle: [584; 1583; 223; 1]\n"
" Value: 2545\n"
" 46) I2of5, Confidence: 0,50, Page 25, Rectangle: [240; 2536; 1263; 1]\n"
" Value: 89660000002429000411110202208291001225389825\n"
" 47) I2of5, Confidence: 0,50, Page 26, Rectangle: [240; 2539; 1265; 1]\n"
" Value: 89610000002429000411110202208291001225389941\n"
" 48) I2of5, Confidence: 1,00, Page 27, Rectangle: [1814; 312; 226; 1]\n"
" Value: 829571\n"
" 49) I2of5, Confidence: 0,50, Page 27, Rectangle: [231; 2382; 1263; 1]\n"
" Value: 89640000003037000411110202208291001225388431\n"
" 50) I2of5, Confidence: 0,50, Page 28, Rectangle: [231; 2533; 1263; 1]\n"
" Value: 89660000003037000411110202208291001225388307\n"
" 51) I2of5, Confidence: 0,50, Page 29, Rectangle: [582; 1349; 159; 1]\n"
" Value: 4416\n"
" 52) I2of5, Confidence: 0,50, Page 29, Rectangle: [237; 2455; 1265; 1]\n"
" Value: 89670000003037000411110202208291001225390079\n"
" 53) I2of5, Confidence: 0,50, Page 30, Rectangle: [1932; 528; 140; 1]\n"
" Value: 0884\n"
" 54) I2of5, Confidence: 0,50, Page 30, Rectangle: [269; 552; 136; 1]\n"
" Value: 8222\n"
" 55) I2of5, Confidence: 0,50, Page 30, Rectangle: [231; 2527; 1265; 1]\n"
" Value: 89670000003012000411110202208291001225390108\n\n"
" Decoding took: 1,705 seconds.\n"
" Preparations: 1,232 seconds.\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