in reply to Substitute for variable-length look-behind?
So, IMO, the safest way is to use two patterns. I'm not sure if you can integrate it into one pattern, I doubt it, so that you can still simply make the whole match fail if the lookbehind fails. Two independent matches won't do that. Anyway, enough blahblah, here's my coarse idea:
For example:my $success; while(/PATTERN/g) { if(substr($_, 0, $-[0]) =~ /LOOKBEHIND\z/) { # got a match! $success = 1; last; } }
printing:$_ = 'bar bar obar foooooobar bar'; my($success, $start) = 0; while(/bar/g) { if(substr($_, 0, $start = $-[0]) =~ /fo+\z/) { # got a match! $success = 1; last; } } print "$success: $start\n";
1: 35Using $start, the start position of the outer match, you can try again if you want, to get the captured values and @- and @+. For some odd reason, capturing @- and @+ in the loop made it loop forever. *shrug*
|
|---|