tags:

views:

131

answers:

3

In the past it was my understanding that the Lat/Lon of an airport had to be on the same line (L 300216 0915302 '2425 29865997) with 300216/0915302 being the Lat/Lon. I just found out that the users can also put the Lat/Lon on different lines.

I  ARA                                    '* ACADIANA  AIRPORT         29865996    
                L    300216                               '2425     29865997    
                     0915302                              '2425     29865998    
                S    MSY                                            29865999    
                M    05E                                            29866000    
                P    100  0300                                      29866001    
                P    239  3405                                      29866002    
                P    999  7001  O                                   29866003

How do I amend my RegEx to trap any 6 digits followed by 7 digits preceded by an L with no alphas between?

Thanks!

A: 

Try the following. Based on your summary I had it match any group of 6 digits, followed by any length of whitespace including new lines, then followed by an L and 7 digits

\d{6}[\s\n]*L\s*\d{7}

I've used the .Net form of regular expression. If you're using a different engine could you post which one? This will also only work against the ASCII character set.

JaredPar
+1  A: 

As for matching

any 6 digits followed by 7 digits preceded by an L with no alphas between

you can use the pattern:

\bL\s*\d{6}\s*\d{7}\b

This will match

L(any amount of whitespace)dddddd(any amount of whitespace)ddddddd

surrounded by boundaries. When it comes to matching across multiple lines, this is usually a flag you can set with the regex engine you're using. The \s will match the newlines just fine, but only if you have the multi-line flag set.

dustyburwell
"The \s will match the newlines just fine, but only if you have the multi-line flag set." - no, \s always matches newlines. The multiline flag changes the behavior of the ^ and $ anchors, and the single-line flag lets the dot metacharacter match newlines. (Except in Ruby, where multiline mode is the same as what everyone else calls single-line mode, and there is no "single-line" modifier.)
Alan Moore
Oh, hmmm... Thanks for the feedback. To be honest, my regexfu needs some work, at least when it comes to how the engine works and which flags to set when.
dustyburwell
+1  A: 

I see eight digits in the right hand column, not seven. Am I viewing that wrong? So I think the question isn't quite what the previous answers seem to be answering. The seven digits are actually on the next line.

Also, this looks like fixed length column output to me, so if you know the numbers of columns, you can gain significant speed by using exact numbers instead of the * modifier.

So if "x" is the number of columns between L and the 6 digits, and "L" is in the first column,

$text =~ m/L\s{x}(\d{6}).*[\r\n]\s\s{x}(\d{7})/

looks as if it should match. Not sure what else might be in the file to deal with, but it's somewhere to start.

$1 = first block of digits (6), $2 = 7 digits on the next line. (using perl syntax, adjust as needed for other implementations)

Devin Ceartas