develooper Front page | perl.perl5.porters | Postings from September 1999

Re: qr{ } and (?=..)

From:
Ilya Zakharevich
Date:
September 4, 1999 22:26
Subject:
Re: qr{ } and (?=..)
Message ID:
19990905012605.B5566@monk.mps.ohio-state.edu
On Sat, Sep 04, 1999 at 09:42:19PM -0600, Ed Peschko wrote:
> 1) (?=$compiledregex) doesn't work. A pattern that matches $re will
> return null if (?=) is
>     wrapped around it.

  perl -wle "$rex = qr/a/; print 12 if 'bab' =~ /b(?=$rex)/"
  12

> 2) matching parens inside of the qr, such as:
>     $regex = qr{ (... (?p{ $qr }) ...) }x;
>     or
>     $regex = qr{ ... (?p{ ( $qr ) }) ... }x;
> 
>     seem to match only once, ie: the 'topmost' match. It would be IMO
> much more
>     interesting and useful if they set $1, $2, $3, $4, $5, etc. so a
> match on
>     '( a ( b c ) ( d e ) )' would set:
>     $1 == '(a ( b c ) ( d e ) )'
>     $2 == '( b c )'
>     $3 == '( d e )'
>     etc.

Can you describe *semantic* of (?p{}) which would lead to such a
behaviour?

> Regarding point #2, is there an array which holds a synonym to '$1'
> '$2', etc? If your
> regular expressions can have an indeterminant number of return values to
> them, I think this
> would be an easy way to keep track of them.

@+/@-?

Ilya



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