Best way to find pattern 6 digit 7 digits space ###### ####### with VB.NET

Parsing a text file in vb.net and need to find latitude and longitude in these two sections of text. The pattern takes 6 digits of a space of 7 digits (364800 0953600). Samples consist of two different map files and have slightly different formats.

I 2H02 364800 0953600 '                 SEC72                           10496300-
I 2H05 360100 0953645 '                               ZFW J602 ZME 2A93 10496400-
I 2H06 361215 0952400 '                 SEC72                  ZME 2A75 10496500-
I 2H07 361715 0951145 '                 SEC27/72               ZME 2A78 10496600-
I 2H08 362025 0950100 '                 TUL                    ZME 2A69 10496700-
I 2H10 360800 0952915 '                                        ZME 2A85 10496800-
I 2H11 362500 0955015 '                 SEC62/72                        10496900-
I 2H14 364145 0954315 '                 TUL                             10497000-


I A85A                  'AL851                                50591 REF 33393944 
         391500 0831100 '                                     50591 REF 33393945 
I A85B                  'AL851                                50591 REF 33393946 
         374500 0825700 '                                     50591 REF 33393947 
I A87A                  'AL871                               111592 REF 33393948 
         402050 0814420 '                                    111592 REF 33393949 
I A87B                  'AL871                               111592 REF 33393950 
         400449 0814400 '                                    111592 REF 33393951 
I A87C                  'AL872                              '030394 GDK 33393952 
         392000 0810000 '                                   '030394 GDK 33393953

      

Thank,

Dave

0


source to share


4 answers


Dim matches As MatchCollection
Dim regex As New Regex("\d{6} \d{7}")
matches = regex.Matches(your_text_string)

      



+6


source


A simple regex should do this:



[0-9]{6} [0-9]{7}

      

+6


source


.....

(?<First>\d{6})\s(?<Second>\d{7})

      

+2


source


Make a simple group capture. It looks like your RegEx formula will be simple enough to handle both scenarios (waste a bit on space detection). Then you can access the properties of the group to match (either by name or just by the underlying index) and get the data you want.

0


source







All Articles