local our @results; # Not "my".
/(\d\d)(?{ push @results, $1 })(?!)/;
| [reply] [d/l] |
Thanks!
I guess magic (?!) do all the job
| [reply] |
(?!) never succeeds (like 5.10's (?*FAIL)), so it force the regexp engine to backtrack and find another match if there is one.
| [reply] [d/l] [select] |
Which is to be expected, because my approach never matches anything in the "real body" of the regular expression. If you want different behaviour of the regex engine, you can only achieve that by making it match different things, which will result in the match variables containing different values. If you want to keep the behaviour of $`, $& and $', then you will need to fiddle with pos. You haven't stated why you don't want to do that.
| [reply] [d/l] [select] |
I think dealing with pos will result in ugly code: maybe code with cycle over string length or time consuming code.
So you mean perl regexps are always greedy: they match as much as possible and there's no way to configure them beside your approach with (?= ) ?
| [reply] |
| [reply] |
See Regexp::Exhaustive to get every possible match of a pattern against a string. It supports the use of $& et al (without global penalty).
use Regexp::Exhaustive 'exhaustive';
my @matches = exhaustive(
'asdf' => qr/..??/,
qw[ $` $& $' ],
);
printf "%s<%s>%s\n", @$_
for @matches;
__END__
<a>sdf
<as>df
a<s>df
a<sd>f
as<d>f
as<df>
asd<f>
lodin | [reply] [d/l] [select] |
Nice package. Thanks.
Investigation of code in Regexp/Exhaustive.pm showed there's constructions like in ikegami's post: <(?!)/tt> and (?{push @array, ...})
| [reply] |
So, have the regex engine do what it does best, that is, return the longest matching string. Then, have a routine that takes that string and provides the permutations.
s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s
|-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,,
$|=1,select$,,$,,$,,1e-1;print;redo}
| [reply] [d/l] |