p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB How-To (http://p2p.wrox.com/forumdisplay.php?f=78)
-   -   Regex with Special Characters (http://p2p.wrox.com/showthread.php?t=51417)

hugh@kmcnetwork.com December 11th, 2006 06:45 PM

Regex with Special Characters
Hello Everyone and thanks for your help in advance. I am working on an application that needs to be able to parse the following strings out of a large block of text:


The strings are using the * character for field delimiters (brilliant) and each stringn ends with the ~ character. The "NM1*IL*1*" is the same for all strings and the "MI" in the middle is also constant. Beyond that, everything is alpha or numeric. I'm really having a rough time with this because of all of the special characters. Any help on this topic would be greatly appreciated. Thanks.

gbianchi December 12th, 2006 08:41 AM

hi there..

what did you try??
what's your specific problem??

did you try for example SPLIT?



hugh@kmcnetwork.com December 13th, 2006 09:28 PM

Here is the general idea of what I am trying to do. I am working on a healthcare application that receives a text file in the HL7 format. HL7 uses a very odd file format that utilizes the * character for column separators and the ~ as the line terminator. So, for example, the first line could be:

ISA*00* *00* *ZZ*100000 *ZZ*71160~

The next line might be:

GS*HB*77027*71160*20061211*10341367*4*X*004010X092 A1~

Each element separated by a * character has a different meaning based on the beginning of the line (for example ISA vs. GS). The beginning of the line may vary slightly, such as GS*HB or GS*H1. So it owuld be advantageous to be able to match each line that starts with GS and ends with~. Some GS lines my have 5 elements, others may have 7, others may have 9. So identifying each type of line is needed to parse the file properly (couldn't they just use XML :)). But I can't figure out exactly how to do this.

Any insight is greatly appreciated. Thanks.

Shasur December 14th, 2006 01:42 AM

Dim arTemp() as string

arTemp = Split("YourStringHere")

IF ubound(arTemp) = 7 then

ElseIF ubound(arTemp) = 9 then


End if

This should work.

If you are bit averse on arrays, ou can do the same in Regular Expressions



BrianWren December 15th, 2006 03:16 PM

Sililar to what Shasur proffered:

    Dim i as integer
    Dim arTemp As String
    arTemp = Split(<Your String Here>, "*")

    Select Case arTemp(0)
        Case "GS"
            ' Do an iterative process here.
            For i = 2 To Ubound(srTemp)
                ' . . .
            Next i

            ' or
            Select Case arTemp(1)
                Case "HB"
                    ' . . .
                Case "H1"
                    ' . . .
            End Select
        Case "ISA"
            [green]' . . .
    End Select

All times are GMT -4. The time now is 11:11 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.