On Jan 25, 2016, at 4:59 PM, Shawn H Corey wrote:
>
> Use the negative match operator !~
>
> if( $QUERY_STRING !~ m{ itemid = [-0-9A-Za-z_]+? (?: \& | \z ) }msx ){
> print "bad: $QUERY_STRING\n";
> }
Thanks for that, Shawn. It works perfectly except for one criteria
that I inadvertently forgot to include. It's possible that the string will
_not_ contain the itemid parameter at all. When that's missing, the regex
matches and it shouldn't. I guess that's why I was trying to stay with the
positive match operator.
I tried inverting your regex:
if ( $QUERY_STRING =~ m/ itemid= .*? [^-0-9A-Za-z_]+? .*? (?: \& | \z ) /sx ) {
say "bad: $QUERY_STRING";
}
but that doesn't work either. It catches even good item numbers.
In the meantime, I got it to work by grabbing the itemid and working
with that separately:
my $item_id = $1 if ($QUERY_STRING =~ m/ itemid=([^&]*) /x);
if ( $item_id =~ m/ [^a-zA-Z0-9_-] /x ) { ...
however, I'd like to do that with a single line, if possible, so I don't have
to create a new variable just for that.
Thanks,
Frank
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/