in reply to Replace zero-width grouping?
Move the loop out of the regex.
$_="17341234"; 1 while s/(.)(...)\1/A$2B/; print "$_\n"
Added: Also - if you need to prevent restarting the regex for some reason, you can add some additional code and still get that. The addition of the eval block and the substr() might be more expensive than starting over - I'll leave that to someone else to benchmark. (and on varying size data)
$_="17341234"; $r = 0; 1 while substr($_,$r) =~ s/(.)(...)\1(?{local $r = pos() - 3})/A$2B/; print "$_\n"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Replace zero-width grouping?
by tinypig (Beadle) on May 06, 2003 at 20:40 UTC | |
|
Re: Re: Replace zero-width grouping?
by BrowserUk (Patriarch) on May 07, 2003 at 16:31 UTC | |
by diotalevi (Canon) on May 07, 2003 at 16:58 UTC |