[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] Perl regexp problem...



On Sun, May 14, 2006 at 12:37:29AM -0500, Daniel Linder (dan@linder.org) wrote:
> For example, this line:
> 
> ^var1=(?i)(.*)(5705)(.*)
> 
> will find all lines that begin with "var1=", followed byt any
> characters, then 5705, then any other characters.  This filter works
> fine.

Actually, that breaks down to

    ^var1=      beginning of the line, and then "var1="
    (?i)        an optional "i"
    (.*)        any string
    (5705)      the string "5705"
    (.*)        any other string

The (.*) at the end is useless because it will always match in this
case, and at the end of the line, you don't care.


> What I want to do is write a filter that finds the opposite lines; i.e all
> lines that begin with "var1=" but do not have 5705 in their
> value.  I tried
> 
> ^var1=(?i)(.*)(^5705)(.*)
> 
> but that didn't work...

That's because the ^ is only negation in a character set, as when you
say [^aeiou] to mean "any character except the vowels".

Probably the simplest way to do this is to have two regexes.

    if ( $line =~ /^var1=/ && $line !~ /5705/ ) {

This says "If it starts with var1=, and it doesn't match 5705 anywhere",
then $line matches.

xoa
-- 
Andy Lester => andy@petdance.com => www.petdance.com => AIM:petdance