[PLUG] Perl regex query

Bill Thoen bthoen at gisnet.com
Tue Feb 7 19:31:16 UTC 2006


Last week I was asking questions about sed, and as was pointed out, the
answer was Perl. But I still have questions regarding some tricky stuff
with regex epressions. I've orderd a copy of "Mastering Regular
Expression", but while I'm waiting for it to arrive I hope someone here can
help me with another problem.

Basically, how do you specify a multi-character regex pattern that may 
repeat for up to 4 times? For example, I'm trying to pick out some land 
parcel quarter-section descriptions that look something like the 
following:

N2SWSE
SWNENENW
...

The first one means "the north half of the southwest of southeast corner of
the section, and the second means the southwest of the northeast of the
northeast of the northwest corner of a section. Essentially each "quarter"
can be described as one of the following: NE, SE, SW, NW, N2, E2, S2, W2,
and there may be none to four of them in the description. These strings may
or may not be delimited by spaces (or dashes or a slash... in the table I
have, these vary) so for example, you might have a complete descriptions that
look like these:

T47R22/NWNE SEC 12 (township 47, range 22 northwest of the northeast corner 
                    of section 12)
T48R22S13SENENEDOU (twp 48 rge 22, section 13, southeast of the northeast
                    of the northeast corner in the DOUglas township)

So with my feeble knowledge of Perl, I try:

#!/usr/bin/perl
while (<>) {
   if (/((NE|SE|SW|NW|N2|E2|S2|W2){0,4})/) {
      $qtr = $1;
      print $qtr," : ", $_ ;
   }
}

and feed it a file containing records like these:

7          001T47R27/NE4-SEC 6-AITKIN TWP
8          001T47R27/N2SE E2NW E2SW SEC 18 AITKIN TWP
9          001T47R27/N2N2 SEC 7 AITKIN TWP
10         001T47R27/S2NW N2SW NWSE SEC 22 AITKIN TWP
11         001T48R27/S33 S2SE E2NE UNORG T47R27 S4 & 5 AITKIN
12         001T47R27/NW SWNE SEC11 LESS N2NE AITKIN TWP
13         001T47R27/SEC 11 N2NE AITKIN TWP
14         001T47R27/S3&2,S2-SW4,T48R27/S35-S2SE,S36 AITKN TWP

I don't get anything. Can anyone tell me what I'm doing wrong?

TIA,

- Bill Thoen



More information about the PLUG mailing list