perl regex vs text editor syntax
I am having trouble with a regex in perl.
I have an array that looks like this:
Abilene,KS,67410,1019 2000 Ave,38.88254,-97.20204,Grant Town Fire Dist
*Arlington,KS,67514,100 W Main St,Reno County Fire Dist 4
Abilene,KS,67410,1463 3325 Ave,39.079136,-97.1181,Sherman Township
Fire District
*Beattie,KS,66406,305 Whiting St,Beattie Rural Fire District No 3
Agra,KS,67621,1752 E 1100 Rd,39.749302,-99.12297,Phillips County Rural
Fire District 3a
I want to remove all of the (2) lines not containing a valid northern
lattitude within commas ie... ,39.xxxxx,
This will not work for me in perl
$tempContent =~ s/^((?!,\d{1,2}\.\d{1,16},).)*$\n//g;
This works in UltraEdit:
^(?:(?!,\d{1,2}\.\d{1,16},).)*$\r\n
This works also with EditPadPro
^(?:(?!,\d{1,2}\.\d{1,16},).)*$\r\n
as does
^((?!,\d{2,3}\.\d{1,16},).)*$\r\n
It may be a simple fix but I cannot see it.
Thanks
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: perl regex vs text editor syntax
jbl wrote:
> I am having trouble with a regex in perl.
> I have an array that looks like this:
> Abilene,KS,67410,1019 2000 Ave,38.88254,-97.20204,Grant Town Fire Dist
> *Arlington,KS,67514,100 W Main St,Reno County Fire Dist 4
> Abilene,KS,67410,1463 3325 Ave,39.079136,-97.1181,Sherman Township
> Fire District
> *Beattie,KS,66406,305 Whiting St,Beattie Rural Fire District No 3
> Agra,KS,67621,1752 E 1100 Rd,39.749302,-99.12297,Phillips County Rural
> Fire District 3a
>
> I want to remove all of the (2) lines not containing a valid northern
> lattitude within commas ie... ,39.xxxxx,
> This will not work for me in perl
> $tempContent =~ s/^((?!,\d{1,2}\.\d{1,16},).)*$\n//g;
>
> This works in UltraEdit:
> ^(?:(?!,\d{1,2}\.\d{1,16},).)*$\r\n
>
> This works also with EditPadPro
> ^(?:(?!,\d{1,2}\.\d{1,16},).)*$\r\n
> as does
> ^((?!,\d{2,3}\.\d{1,16},).)*$\r\n
>
> It may be a simple fix but I cannot see it.
> Thanks
I presume you're trying to use $ to match before a newline at the end of
the string, but you're actually using the $\ (output record separator)
variable followed by 'n'. There's no need to use both, and just a dollar
is conventional.
After that, I don't really understand your regex. You are matching a
line which is an indefinite repetition of anything that doesn't match
/,\d{1,2}\.\d{1,16},/ followed by a single wild character /./. How is
that supposed to work?
Do you really have an array? Writing a text substitution will leave you
with an array with some elements blank, and $tempContent will be set,
not to content of any sort, but to the number of substitutions made -
presumably 1 or 0.
It sounds like you may need grep, with a simpler regex. How about
my [at] filtered = grep(not(m/\b\d+\.\d+\b/), [at] data);
HTH,
Rob
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/