develooper Front page | perl.beginners | Postings from July 2003

Re: Regular Expression

Thread Previous
From:
Kevin Pfeiffer
Date:
July 16, 2003 01:22
Subject:
Re: Regular Expression
Message ID:
2551551.OMl2ZKpxN0@sputnik.tiros.net
In article <20030715205252.55680.qmail@onion.perl.org>, Paul D. Kraus wrote:

>> I am having a hard time getting a regular expression to work the way i
> want
>> it to.  Take the following text: bla bla bla (la la) bla bla (di da)
> 
> my ( $var1, $var2 ) = ( $1, $2 ) if /$inputstring =~ m/bla bla bla (la la)
> bla bla (di da)
> 
> $1 gets la la
> $2 gets di da

But his line has parentheses. I think these have to be escaped if you want 
to match on them:  \(  and \) otherwise they become capturing "Klaemmer". 
(Right?)

Here is what I came up with (I'm sure someone can do this more elegantly):

if ($line =~ /[^(]*\(([^)]+)\)[^(]*\(([^)]+)\)/) {
   print "$1 and $2\n";
}


-- 
Kevin Pfeiffer
International University Bremen

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About