[Omaha.pm] Perl regexp problem...

Daniel Linder dan at linder.org
Tue May 16 09:28:09 PDT 2006



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 at 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 at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/omaha-pm/attachments/20060516/d4ab0d86/attachment.html 


More information about the Omaha-pm mailing list