# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"Total statistics:\s+\K\d+"
test_str = "{\"logSystem\":[[2019,4,26,10,37,0,44872,\"Battery Charge Started! 17.0°C 21.05Volt\",\"#000099\",\"normal\"],[2019,4,26,10,37,0,44871,\"Total statistics: 334418m, 23862min, blade on time: 21289min\",\"#2E2EFE\",\"bold\"],[2019,4,26,10,37,0,44870,\"Current cut statistics: 2m, 0min, blade on time: 0min\",\"#2E2EFE\",\"bold\"],[2019,4,26,10,37,0,44869,\"Landroid at home\",\"#996600\",\"normal\"],[2019,4,26,10,37,0,44868,\"Landroid searching home\",\"#996600\",\"normal\"],[2019,4,26,10,36,46,44867,\"Landroid following wire\",\"#996600\",\"normal\"],[2019,4,26,10,36,43,44866,\"Landroid searching wire\",\"#996600\",\"normal\"],[2019,4,26,10,36,41,44865,\"[auto] message reset Close windows to go charge\",\"#FFA800\",\"normal\"],[2019,4,26,10,36,40,44864,\"Landroid start sequence\",\"#996600\",\"normal\"],[2019,4,26,10,36,40,44863,\"Home button pressed\",\"#FFA800\",\"normal\"],[2019,4,26,10,36,38,44862,\"[user] message reset Upside Down\",\"#FFA800\",\"normal\"],[2019,4,26,10,34,47,44861,\"Landroid Upside Down 41x-2y-0.6z\",\"#FF0000\",\"bold\"],[2019,4,26,10,34,42,44860,\"[user] message reset Trapped\",\"#FFA800\",\"normal\"],[2019,4,26,10,34,35,44859,\"[auto] message reset Outside working area\",\"#FFA800\",\"normal\"],[2019,4,26,10,29,20,44858,\"Landroid in idle state 16.4°C 20.33 Volt\",\"#996600\",\"normal\"],[2019,4,26,10,29,20,44857,\"Total statistics: 334416m, 23862min, blade on time: 21289min\",\"#2E2EFE\",\"bold\"],[2019,4,26,10,29,20,44856,\"Current cut statistics: 71m, 8min, blade on time: 0min\",\"#2E2EFE\",\"bold\"],[2019,4,26,10,29,20,44855,\"!ERROR! outside wire timeout\",\"#FF0000\",\"bold\"],[2019,4,26,10,28,54,44854,\"[Wifi] Connected\",\"#2E2EFE\",\"normal\"],[2019,4,26,10,28,36,44853,\"[Wifi] Connection Lost!\",\"#2E2EFE\",\"normal\"],[2019,4,26,10,25,6,44852,\"Landroid following wire\",\"#996600\",\"normal\"],[2019,4,26,10,25,4,44851,\"Landroid searching home\",\"#996600\",\"normal\"],[2019,4,26,10,24,54,44850,\"Landroid following wire\",\"#996600\",\"normal\"],[2019,4,26,10,24,54,44849,\"Landroid searching home\",\"#996600\",\"normal\"],[2019,4,26,10,24,28,44848,\"Landroid following wire\",\"#996600\",\"normal\"],[2019,4,26,10,24,25,44847,\"Landroid searching wire\",\"#996600\",\"normal\"],[2019,4,26,10,23,42,44846,\"Landroid following wire\",\"#996600\",\"normal\"],[2019,4,26,10,23,39,44845,\"Landroid searching wire\",\"#996600\",\"normal\"],[2019,4,26,10,22,58,44844,\"Landroid following wire\",\"#996600\",\"normal\"],[2019,4,26,10,22,54,44843,\"Landroid searching wire\",\"#996600\",\"normal\"],[2019,4,26,10,22,54,44842,\"Flowerbed loop detected leaving...\",\"#FFA800\",\"normal\"],[2019,4,26,10,21,36,44841,\"Landroid following wire\",\"#996600\",\"normal\"],[2019,4,26,10,21,22,44840,\"Landroid searching wire\",\"#996600\",\"normal\"],[2019,4,26,10,21,22,44839,\"[Battery LOW] homing req, status: 14.8°C 23.65Volt\",\"#FFA800\",\"normal\"],[2019,4,26,10,21,13,44838,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,26,10,21,10,44837,\"[auto] message reset Close windows to start\",\"#FFA800\",\"normal\"],[2019,4,26,10,21,9,44836,\"Landroid start sequence\",\"#996600\",\"normal\"],[2019,4,26,10,21,9,44835,\"Start button pressed\",\"#FFA800\",\"normal\"],[2019,4,26,10,21,7,44834,\"[user] message reset Trapped\",\"#FFA800\",\"normal\"],[2019,4,26,10,21,3,44833,\"[Wifi] Connected\",\"#2E2EFE\",\"normal\"],[2019,4,26,10,20,51,44832,\"Landroid in idle state 14.7°C 24.20 Volt\",\"#996600\",\"normal\"],[2019,4,26,10,20,51,44831,\"Power On v: 2.45\",\"#000000\",\"bold\"],[2019,4,25,19,36,18,44830,\"Shutdown 24.07Volt\",\"#000000\",\"bold\"],[2019,4,25,19,36,18,44829,\"Landroid idle shutdown timer\",\"#FFA800\",\"normal\"],[2019,4,25,19,16,18,44828,\"Landroid in idle state 37.6°C 24.05 Volt\",\"#996600\",\"normal\"],[2019,4,25,19,16,18,44827,\"Total statistics: 334345m, 23854min, blade on time: 21289min\",\"#2E2EFE\",\"bold\"],[2019,4,25,19,16,18,44826,\"Current cut statistics: 1087m, 76min, blade on time: 76min\",\"#2E2EFE\",\"bold\"],[2019,4,25,19,16,17,44825,\"Landroid following wire\",\"#996600\",\"normal\"],[2019,4,25,19,16,15,44824,\"Landroid searching home\",\"#996600\",\"normal\"],[2019,4,25,19,16,9,44823,\"Landroid following wire\",\"#996600\",\"normal\"],[2019,4,25,19,16,9,44822,\"Landroid searching home\",\"#996600\",\"normal\"],[2019,4,25,19,16,5,44821,\"Landroid following wire\",\"#996600\",\"normal\"],[2019,4,25,19,15,58,44820,\"Landroid lift recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,15,57,44819,\"Landroid following wire\",\"#996600\",\"normal\"],[2019,4,25,19,15,55,44818,\"Landroid searching home\",\"#996600\",\"normal\"],[2019,4,25,19,15,50,44817,\"Landroid following wire\",\"#996600\",\"normal\"],[2019,4,25,19,15,50,44816,\"Landroid searching wire\",\"#996600\",\"normal\"],[2019,4,25,19,15,50,44815,\"[Battery LOW] homing req, status: 37.6°C 23.97Volt\",\"#FFA800\",\"normal\"],[2019,4,25,19,15,28,44814,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,15,24,44813,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,12,26,44812,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,12,19,44811,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,10,49,44810,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,10,44,44809,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,9,22,44808,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,9,18,44807,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,8,32,44806,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,8,27,44805,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,8,26,44804,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,8,22,44803,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,7,55,44802,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,7,51,44801,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,6,0,44800,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,5,55,44799,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,5,6,44798,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,5,2,44797,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,4,10,44796,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,4,5,44795,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,3,29,44794,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,3,25,44793,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,3,25,44792,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,3,21,44791,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,2,58,44790,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,2,54,44789,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,2,52,44788,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,2,47,44787,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,2,43,44786,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,2,39,44785,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,2,23,44784,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,2,18,44783,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,2,6,44782,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,2,2,44781,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,1,0,44780,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,0,54,44779,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,0,54,44778,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,0,48,44777,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,19,0,46,44776,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,19,0,42,44775,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"],[2019,4,25,18,59,21,44774,\"Landroid grass cutting\",\"#996600\",\"normal\"],[2019,4,25,18,59,17,44773,\"Landroid trapped recovery procedure\",\"#996600\",\"normal\"]]}"
matches = re.search(regex, test_str)
if matches:
print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group()))
for groupNum in range(0, len(matches.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.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