[PLUG] Perl regex query
Aaron Burt
aaron at bavariati.org
Wed Feb 8 00:39:48 UTC 2006
On Tue, Feb 07, 2006 at 12:31:16PM -0700, Bill Thoen wrote:
> 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," : ", $_ ;
> }
> }
Might try a couple things: "(NE|SE|SW|NW|N2|E2|S2|W2)+" (match one or
more of those) and you might also see how things work with the split
command. The \b (word boundary) metacharacter might come in handy here.
A successive series of search/replace, and split might do the job.
I Googled for "perl regex" and found this to be nifty:
http://www.perl.com/doc/manual/html/pod/perlre.html
And do you have "Learning Perl"? The author posts here sometimes... ;)
More information about the PLUG
mailing list