Juerd:
> Ruud H.G. van Tol:

>> s/($search)/*\1*/go
>
> \1 in Perl 5 is bad style and emits a warning

The point was to give \1 and \&, in the replace part, a very limited
scope.

Maybe even better to limit \1 to the first '(?: ... )' in the search
part.

  s/(?:$search)(?:.\1)+/\1/go

  xy.xy.xy.xy --> xy


But if Perl6 can do the same with

  s/($search)(.\1)+/$1/go

by detecting that the possible $1 and $2 and $& (or new equivalents) are
(almost certainly) not going to be used, that's of course best.


A '+' can often be optimized to a {2,}. In this case:

  s/($search)+/$1/

only if the resulting count is never used.

-- 
Grtz, Ruud

Reply via email to