Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Person and Vehicle data extraction

Last post 10-12-2008, 7:41 AM by ddrudik. 5 replies.
Sort Posts: Previous Next
  •  10-10-2008, 3:40 PM 47098

    Person and Vehicle data extraction

    Hope someone can help me.  I’m using VB.net to scan a log file that gets written to every few seconds.  I’m using a timer and capturing the appended information since the last scan(every 10 seconds).  I’m then trying to identify the following text patterns and capture the bolded information in an array which will then be exported to an XML file.  There will be many lines of unwanted data prior to and after the relevant data. 

    The data will be structured in the same format for the foreseeable future so I don’t really need the field identifiers but if they need to be in an array so be it.  One problem I have is that the text/log file can accept 2 structures of people and vehicles.  EX 1 & 2 is for the people and 3 &4 is for the vehicles.  Both frameworks seem to have similar construction but one has carriage returns and one is pretty much a single line.

    I was going to use instr and mid functions to parse this data line by line in a loop but stumbled on to regex and thought it might be quicker than checking every line.  The time spent trying to learn and create a complicated pattern is seeming less likely but maybe somebody can help with expertise in this?

    EXAMPLE 1:

     

     

     

     

     

    10/8/2008 13:49:43 = MESSAGIN = STAT --> RF_MSG_DATA_AVAILABLE

    10/8/2008 13:49:43 = MESSAGIN = USER --> MESSAGING state:276

    10/8/2008 13:49:43 = MESSAGIN = RECV -->

    DF/JOHN/B/VAN DOE/M/010189                  09/15/08 07.50AM CT

    > > > > > > > >THIS RECORD DISPLAYS AN ID-CARD< < < < < < < <

    DID/X000-0000-0000-00

    NAM/VAN DOE, JOHN B             

    STR/1234 MAIN ST

    STR/1234 MAIN ST
    CTY/MYTOWN        ST/WI ZIP/54901 CT/GRANT   

    SEX/M RAC/WHITE  DOB/010189 HGT/502 WGT/115 HAI/BLND EYE/BLUE DONR/  Y

    LT= RGLR                      ISS= 08/19/2001 EXP= 02/12/2009 AT= RNW

        CLASSES=  D                                                     

        STATUS=  VAL                                                    

        PRDT#= 36150-973-102                                            

    ---------------------------------------------------------------------

    LT= REGI INSTRPMT             ISS= 06/13/1995 EXP= 12/13/1995 AT= ORG

        CLASSES=  D                                                     

        STATUS=  EXP                                                     

        PRDT#= 12240-951-640                                            

    =====================================================================

    ( PAGE  1 - END   )

    Example 2:

     

     

     

     

     

    10/8/2008 13:49:43 = MESSAGIN = STAT --> RF_MSG_DATA_AVAILABLE

    10/8/2008 13:49:43 = MESSAGIN = USER --> MESSAGING state:276

    10/8/2008 13:49:43 = MESSAGIN = RECV --> MFR_1275541_*Con;W4_MP.E64MS_10/08/08 13:50:01_0_nOQ 12:38:41_nOQ 12:38:41 /0781 1809 F222 WI0710005 DOT 171236 130 10/08/08 12:39 01 OF 01 DF/JOHN/B/VAN DOE/F/010660 10/08/08 12.39PM CT DID/ X000-0000-0000-00NAM/ VAN DOE, JOHN B STR/1234 MAIN ST CTY/ ANYTOWN ST/ WI ZIP/54901 CT/WINNEBAGO SEX/F RAC/WHITE DOB/010660 HGT/504 WGT/105 HAI/BLND EYE/BLUE DONR/ Y LT= RGLR ISS= 12/26/2003 EXP= 01/06/2012 AT= RNW CLASSES= D STATUS= VAL REST= GLS PRDT#= 40364-920-072 ===================================================================== 051987 FORMER/ X000-0000-0000-00NAM/WALKER, JOHN B 080603 091803 CONVICT SI 04 CT/WAUPACA OPR AS=D ( PAGE 1 - END )

    EXAMPLE 3:

     

     

     

     

     

    10/8/2008 13:49:31 = SCAEXT2  = STAT --> RF_MSG_SIGNAL_LEVEL:92

    10/8/2008 13:49:31 = SCAEXT2  = USER --> SCAEXT2 state:276

    10/8/2008 13:49:33 = MESSAGIN = STAT --> RF_MSG_DATA_AVAILABLE

    10/8/2008 13:49:33 = MESSAGIN = USER --> MESSAGING state:276

    10/8/2008 13:49:33 = MESSAGIN = RECV --> MFR_1275540_*Con;W4_MP.E64MS_10/08/08 13:49:46_0_QOQ 13:48:43_QOQ 13:48:43 /0173 1809 F611 WI0710005 DOT 193240 133 10/08/08 13:49 01 OF 01 INP Input Request: INP1 Plate: 123ABC Type: AUT 10/08/2008 01.49 PM CT INP2 Response 1 of 1 PLT Plate Information: PLT1 NBR: 123ABC / Type: AUT - AUTOMOBILE REG Registration Information: REG1 Type: AUTO / Last Updated: 10/18/2007 at 04:00 PM REG2 Status: EXPIRED REG3 Period: ANNUAL / Expires: 10/31/2003 OWN Owner Detail: OWN1 1st: VAN DOE JOHN B OWN2 DOB: 01/26/1975 / DID: X0000000000000 OWN1 AND: VAN DOE JANE R OWN2 DOB: 08/26/1977 / DID: X0000000000000 OWN3a 1255 VAN HORN ST OWN3d BERLIN WI 54923 VEH Vehicle Information: VEH2   12345678912345678 / TRUCK VEH3  Year: 2002 / Make: FORD VEH4 Model: F150 SUPERCREW / Style: PICKUP___0_

    EXAMPLE 4:

     

     

     

     

     

    09/15/2008 10:24:24 = GPS      = USER --> Sending data to SCASocket: >RPV55513+2220370-0774478400807412<

    09/15/2008 10:24:26 = STATE    = STAT --> RF_MSG_DATA_AVAILABLE

    09/15/2008 10:24:26 = STATE    = USER --> STATE state:276

    09/15/2008 10:24:26 = STATE    = RECV --> SFR_3006412_FORM=TEXT_SUM=DOT _TEXT=Transaction number: 125190

    INP  Input Request:

    INP1   Plate: AB1234 Type: TRK   09/15/2008 10.25 AM CT

    INP2   Response 1 of 1

    PLT  Plate Information:

    PLT1   NBR: AB1234 / Type: LTK - LIGHT TRUCK

    REG  Registration Information:

    REG1   Type: LIGHT TRUCK / Last Updated: 07/07/2008 at 12:00 PM

    REG3   Period: ANNUAL / Expires: 08/31/2009

    REG4   Carrier: none / VEH GRS WT: 6000LB

    OWN  Owner Detail:

    OWN1   1st: VAN DOE JOHN B

    OWN2   DOB: 01/26/1955 / DID: S1234567891234

    OWN3a    1234 MAIN ST

    OWN3d    MILWAUKEE WI 53201

    VEH  Vehicle Information:

    VEH2   12345678912345678 / TRUCK

    VEH3   Year: 2002 / Make: FORD

    VEH4   Model: F150 SUPERCREW / Style: PICKUP

    TTL  Title Information:

    TTL1   Title Number: 1234567891234

    __0_0_

    09/15/2008 10:24:26 = USERREGI = USER --> ALARM - Service: STATE State:True AlarmFile:Blank.wav

    09/

  •  10-10-2008, 8:12 PM 47099 in reply to 47098

    Re: Person and Vehicle data extraction

    I would recommend you check with the source of this data to see if this data as shown in your log file has been modified from the original, usually there is a "." or some other character to show where a field ends, otherwise parsing a file with spaces etc. in the values would prove problematic.  For a similar question:

    http://regexadvice.com/forums/thread/45419.aspx


  •  10-10-2008, 8:56 PM 47101 in reply to 47099

    Re: Person and Vehicle data extraction

    Unfortunately this is all we are allowed.  The source is a product from Motorola who are very particular in their licenses and closed access.  I wrote a parsing routine in VBA with a series of IF...THENs but thought the regex would be faster, particularly for how frequent it will be scanned.  Makes me feel a tad better that I wasn't able to get it all sorted out.  Believe it or not this: [/< ]+ little thinga ma jigger sorts out all the components into an array that I could step through.
  •  10-11-2008, 12:32 AM 47102 in reply to 47098

    Re: Person and Vehicle data extraction

    Consider this example for your first data example:

    http://www.myregextester.com/?r=360

    You can send the data one record at a time to it, no need to send it line-by-line.  You could add named capture groups to help organize your returned capture groups, capture group 1 is the variable name and capture group 2 is the variable value.

    Consider this modfiied version of the VB.NET code that uses named capture groups:

    http://pastebin.com/f7d0121fc

    For the example I copied the text from your example 1 and saved it into an empty text file named input.txt.

    The code removes the additional LT= sections from the file (based on the ----- line) since you seemed to want to ignore them, if you need those additional sections the code can be modified to handle those duplicate var names.

    Note that the characters included in my character sets in the example might only fit your given example, modify the character sets as needed to match the range of your real data.


  •  10-12-2008, 6:57 AM 47111 in reply to 47102

    Re: Person and Vehicle data extraction

    That is sheer genius!  It seems to work on both data structures as well.  I hope to decipher and modify it to match the vehicle structure as well but I am a happy girl and you are my hero. Big Smile
  •  10-12-2008, 7:41 AM 47112 in reply to 47111

    Re: Person and Vehicle data extraction

    Thanks, glad I could help.
View as RSS news feed in XML