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

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



Andy,

Thanks for the input.  The original problem came from a co-worker of mine who is limited by the third-party program that  only allows the simple regular _expression_ in a text box, so the loop (which was my first though, too) won't work.

If I come up with anything that works I'll be sure to tell everyone.

Dan

On Sun, May 14, 2006 01:14, Andy Lester wrote:
> 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
>


- - - -
"Wait for that wisest of all counselors, time." -- Pericles
"I do not fear computers, I fear the lack of them." -- Isaac Asimov
"Soon we will be able to harness the rotational energy from Orwell's grave to solve all world energy problems." -- /. user GigsVT (208848)
GPG fingerprint:6FFD DB94 7B96 0FD8 EADF 2EE0 B2B0 CC47 4FDE 9B68