# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r" SG_ (\w+) : (\d+)\|(\d+)@[01][+-] \(([0-9E\-\+\.]*),([0-9E\-\+\.]*)\) \[[0-9E\-\+\.]*\|[0-9E\-\+\.]*\] \"([^\"]*)\" Vector__XXX"
test_str = ("VERSION \"\"\n\n\n"
"NS_ : \n"
" NS_DESC_\n"
" CM_\n"
" BA_DEF_\n"
" BA_\n"
" VAL_\n"
" CAT_DEF_\n"
" CAT_\n"
" FILTER\n"
" BA_DEF_DEF_\n"
" EV_DATA_\n"
" ENVVAR_DATA_\n"
" SGTYPE_\n"
" SGTYPE_VAL_\n"
" BA_DEF_SGTYPE_\n"
" BA_SGTYPE_\n"
" SIG_TYPE_REF_\n"
" VAL_TABLE_\n"
" SIG_GROUP_\n"
" SIG_VALTYPE_\n"
" SIGTYPE_VALTYPE_\n"
" BO_TX_BU_\n"
" BA_DEF_REL_\n"
" BA_REL_\n"
" BA_DEF_DEF_REL_\n"
" BU_SG_REL_\n"
" BU_EV_REL_\n"
" BU_BO_REL_\n\n"
"BS_:\n\n"
"BU_:\n\n\n"
"BO_ 777 VBOX_9: 8 Vector__XXX\n"
" SG_ Longitude_48bit : 7|48@0- (1E-07,0) [0|0] \"minutes\" Vector__XXX\n\n"
"BO_ 776 VBOX_8: 8 Vector__XXX\n"
" SG_ Latitude_48bit : 7|48@0- (1E-07,0) [0|0] \"minutes\" Vector__XXX\n"
" SG_ Kalman_filter_status : 56|1@0+ (1,0) [0|1] \"\" Vector__XXX\n\n"
"BO_ 774 VBOX_6: 8 Vector__XXX\n"
" SG_ Vel_Quality : 7|16@0- (0.01,0) [0|0] \"km/h\" Vector__XXX\n\n"
"BO_ 773 VBOX_5: 8 Vector__XXX\n"
" SG_ Trig_Vel_Mph : 55|16@0+ (0.0115078,0) [0|754.163673] \"Mph\" Vector__XXX\n"
" SG_ Trig_Vel_Kmh : 55|16@0+ (0.01852,0) [0|1213.7082] \"Km/h\" Vector__XXX\n"
" SG_ Trig_time : 39|16@0+ (0.01,0) [0|655.35] \"Secs\" Vector__XXX\n"
" SG_ Distance : 7|32@0+ (7.8125E-05,0) [0|335544] \"Metres\" Vector__XXX\n\n"
"BO_ 772 VBOX_4: 8 Vector__XXX\n"
" SG_ Lateral_acceleration : 55|16@0- (0.01,0) [-327.68|327.67] \"G\" Vector__XXX\n"
" SG_ Longitudinal_acceleration : 39|16@0- (0.01,0) [-327.68|327.67] \"G\" Vector__XXX\n"
" SG_ Trig_Dist : 7|32@0+ (7.8125E-05,0) [0|335544] \"Metres\" Vector__XXX\n\n"
"BO_ 771 VBOX_3: 8 Vector__XXX\n"
" SG_ DGPS : 61|1@0+ (1,0) [0|0] \"On\" Vector__XXX\n"
" SG_ Brake_trigger : 60|1@0+ (1,0) [0|0] \"On\" Vector__XXX\n"
" SG_ Vertical_Velocity : 31|16@0- (0.01,0) [0|655.36] \"m/s\" Vector__XXX\n"
" SG_ Altitude_WGS84 : 7|24@0- (0.01,0) [0|42949700] \"metres\" Vector__XXX\n\n"
"BO_ 770 VBOX_2: 8 Vector__XXX\n"
" SG_ Velocity_Mph : 39|16@0+ (0.0115078,0) [0|754.163673] \"Mph\" Vector__XXX\n"
" SG_ Heading : 55|16@0+ (0.01,0) [0|359.99] \"Degrees\" Vector__XXX\n"
" SG_ Velocity_Kmh : 39|16@0+ (0.01852,0) [0|1213.7082] \"Km/h\" Vector__XXX\n"
" SG_ Longitude : 7|32@0- (1E-05,0) [-21474.83648|21474.83647] \"Minutes\" Vector__XXX\n\n"
"BO_ 769 VBOX_1: 8 Vector__XXX\n"
" SG_ Latitude : 39|32@0- (1E-05,0) [-21474.83648|21474.83647] \"Minutes\" Vector__XXX\n"
" SG_ Time_Since_Midnight : 15|24@0+ (0.01,0) [0|0] \"Seconds\" Vector__XXX\n"
" SG_ Sats : 7|8@0+ (1,0) [0|12] \"Sats\" Vector__XXX\n")
matches = re.finditer(regex, test_str, 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