For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > May 2006 > Re: Negated Perl Regexp, Howabout qr in Modules?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Negated Perl Regexp, Howabout qr in Modules?
Xicheng Jia

2006-05-30, 8:01 am

Veli-Pekka T=E4til=E4 wrote:
> Ronny wrote:
> I have a related question here. One case which the so far posted solutions
> don't address is the use of compiled regular expressions with the qr
> operator. Many modules can take qr regular expressions for filtering or
> homing in some particular datum. However, in some cases I'd like to use a
> negated test for matching. I'm not really willing to extend the original
> module code if I can avoid it. So, can one easily negate a qr-regexp when
> the module code supposedly uses =3D~ for testing?


you want to match anything except those matching the qr//
expression???? so you might want to try the following:

my $RE =3D qr/something here/;

if ($v =3D~ /^(?:(?!$RE).)*$/) {
# any string $v that doesnot match $RE
}

(untested)
Xicheng

> PS: The module in this case is:
> Win32::IE::Mechanize
>
> --
> With kind regards Veli-Pekka T=E4til=E4 (vtatila@mail.student.oulu.fi)
> Accessibility, game music, synthesizers and programming:
> http://www.student.oulu.fi/~vtatila/


Mumia W.

2006-05-31, 7:06 pm

Xicheng Jia wrote:
> [...]
> you want to match anything except those matching the qr//
> expression???? so you might want to try the following:
>
> my $RE = qr/something here/;
>
> if ($v =~ /^(?:(?!$RE).)*$/) {
> # any string $v that doesnot match $RE
> }
>
> (untested)
> Xicheng
>


Well, I tested it, and it seems pretty darn good, and just like Ronny, I
might end up using this in my programs if I can figure out how it works.
Thanks Xicheng.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com