in reply to Regex to replace consecutive tokens
An alternative is the sledgehammer approach of retrying until there is nothing more:
1 while $s =~ s/,,/,0,/;
At least in this case, it's not hard to see that this approach will need at most two runs to replace all occurrences properly. Other, more complex regular expressions might need more thought, especially when the strings grow long. Rescanning a string might be more expensive than picking up a bit before where you last left off.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex to replace consecutive tokens
by choroba (Cardinal) on Oct 18, 2013 at 12:47 UTC | |
|
Re^2: Regex to replace consecutive tokens
by wjw (Priest) on Oct 18, 2013 at 14:44 UTC | |
by BrowserUk (Patriarch) on Oct 18, 2013 at 14:53 UTC |