On 14-04-16, 2:20, Robert Klemme wrote:
> Just a caveat: this approach works only because match of your
> capturing extends to the whole expression match. It will break if you
> have text matched before or after the group which should stay as is.
> If that is the case you would have to either use lookaround if
> possible OR introduce groups for the prefix and / or suffix and use
> them to construct the replacement.
>
> I guess this does not apply in your case.

Right, that makes sense; in this case my pattern is just a list of named 
captures union'd together.

The previous implementation used a series of gsub's to replace each 
pattern one at a time (same as your String[/x/,'y'] suggestion), but 
this was slow because it had to traverse a large string several times, 
and I suspect also allocating a whole new string for each iteration.

Thanks!
Andrew Vit