You shouldn't have to run another regexp here. You can just parenthesize this in the regexp passed to `replace` below. The function will get the matched substrings as arguments.