tags:

views:

194

answers:

3

Need to locate the following pattern:

The letter I followed by a space then three alpha numerics followed by a space

"I ALN " "I H21 " "I 31M "

these items are also followed by a lat/lon that is trapped by this expression:

Dim regex As New Regex("\d{6} \d{7}")

Can the expressions be combined to return a match that would look like:

"H21 ###### #######"

Thanks,

Dave

+1  A: 
I ([a-zA-Z\d]{3} \d{6} \d{7})

Match group 1 would contain the three alphanumerics plus the numbers you already catch with your other regex.

EDIT: Does not work because the pattern described in the question does not reflect what the author meant in the first place. What really was meant was first clarified in the comments.

Tomalak
I AAA B SP2 L **400931 0892006** V 006 00 J SPI ' LOGAN CO 10233 10817703-The text that I am trying to capture is AAA and 400931 0892006 from the string above. I am not getting any matches returned.
Sorry, there are no ** before the Lat and Lon 400931 0892006. The string that we are trying to mine from is. I AAA B SP2 L 400931 0892006 V 006 00 J SPI ' LOGAN CO 10233 10817703-
This input does not match the pattern described in your original post. That's why you're not seeing matches.
GalacticCowboy
It would have been nice to have that info from the start.
Tomalak
+4  A: 

/I ([0-z]{3} \d{6} \d{7})/

I don't know VB, but that regex would work with say perl.

Update:
Given the new string provided.. something like this may work (depending on responses to my questions)

/^[A-z] ([0-z]{3}) [A-z] [0-z]{3} L (\d{6} \d{7})/

Matches would then be joined (match 1 containing the AAA, match 2 containing the Lat/Long).

Update #2:
From OP: No on the pattern. The only pattern is I AAA then on the same line the 4000931 0892006. Can you add an OR statement to an expression

You can add an OR, sort of, but I'm uncertain that this is really what you want? This new regex will match I, followed by a space, followed by 3 alpha numeric characters, and then "anything", and the lat/long. Note tho that if there's data in the file or whatever you're parsing that matches a line like that (in that it's "other" data, but follows a similar pattern), you'll probably catch that too.

/^I ([0-z]{3}) .* (\d{6} \d{7})/

shelfoo
A: 

I AAA B SP2 L 400931 0892006 V 006 00 J SPI ' LOGAN CO 10233 10817703-

Above is the text that I am testing against. I am trying to capture AAA and 400931 0892006 . I am not getting any matches returned.

Is the "L" always there?Is it always a pattern of I, 3 alphanumerics, 1 alpha numeric, 3 alpha numerics, L, and then the number string?Is the V always there?Regex's aren't magic, we need to match against a pattern, but we need to know what that pattern actually is to help you out.
shelfoo
No on the pattern. The only pattern is I AAA then on the same line the 4000931 0892006. Can you add an OR statement to an expression?