narainhere has asked for the wisdom of the Perl Monks concerning the following question:
This matches the last 'a' in the string, Now I tried matching the first 'a' in the sting by look-behind assertionmy $str="axx12yya"; if($str=~m/12(?=.*a)/) { print "match \n"; }
I got an error messagemy $str="axx12yya"; if($str=~m/12(?<=a.*)/) { print "match \n"; }
Please explain why this error occurs and how to match the first occurrence of 'a'.One more thing noticed is if I replace the '.*' with \w{2} likeVariable length lookbehind not implemented before HERE mark in regex m +/12(?<=a.* ) << HERE / at test2.pl line 3.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: look-ahead and look behind!!
by moritz (Cardinal) on Oct 22, 2007 at 09:27 UTC | |
|
Re: look-ahead and look behind!!
by GrandFather (Saint) on Oct 22, 2007 at 09:46 UTC | |
by narainhere (Monk) on Oct 22, 2007 at 10:29 UTC | |
by GrandFather (Saint) on Oct 22, 2007 at 10:37 UTC | |
|
Re: look-ahead and look behind!!
by dk (Chaplain) on Oct 22, 2007 at 09:37 UTC | |
|
Re: look-ahead and look behind!!
by Anonymous Monk on Oct 22, 2007 at 09:45 UTC |