in reply to Re: Using lookaround with variables
in thread Using lookaround with variables
Actually, if $pre contains anything that would involve a variable-length match, it just won't work with the look-behind operator:
That is, the regex quantifiers "*", "?", "+" and "{n,m}" cannot be used as such when doing a look-behind (though they will work with look-ahead). If the OP's $pre might ever contain one of these things, putting \Q...\E around it in the regex -- treating them as literals -- will at least make sure the script doesn't crash. -- update: and as ikegami explains below, there's a better way to handle thisperl -e '$pre="x+"; $_="xxFindme"; print "found" if(/(?<=$pre)Findme/) +' # dies with the message: Variable length lookbehind not implemented in regex; marked by <-- HER +E in m/(?<=x+)Findme <-- HERE / at -e line 1.
(I'm sure ikegami knows this already, but it might not have been clear to mwunderlich or other readers.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Using lookaround with variables
by ikegami (Patriarch) on Dec 17, 2008 at 07:19 UTC |