Find Pattern Letter followed by a space, then three alpha digits and then a space

Find the following pattern:

The letter I followed by a space, then three alpha numbers, followed by a space

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

these elements are also followed by lat / lon, which is captured by this expression:

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

Is it possible to combine expressions to return a match that looks like this:

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

Thank,

Dave

0


source to share


2 answers


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

I don't know VB, but this regex will work with the name perl.

Update:
Considering the newline is provided .. something like this might work (depending on the answers to my questions)

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



The matches will then be concatenated (match 1 containing AAA, match 2 containing Lat / Long).

Update # 2:
From OP: Not in the template. The only pattern is AAA and then on the same line 4000931 0892006. Can you add the OR operator to the expression

You can add an OR, sort of, but I'm not sure if this is really what you want? This new regex will match an I, followed by a space, followed by 3 alphanumeric characters, followed by "all" and "lat / long". Note that if there is data in the file or something else that you are parsing that matches such a string (in that it is "different" data, but follows a similar pattern), you will probably figure it out too.

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

+4


source


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

      

Match group 1 will contain three alphanumeric characters plus numbers that you already caught with another regular expression.



EDIT: Doesn't work because the pattern described in the question doesn't reflect what the author had in mind in the first place. What really meant was first clarified in the comments.

+1


source







All Articles