I want to insert a dollar sign at a specific position between two named capturing groups. The problem is that this means two immediately following dollar-signs in the replac
Use this replacement pattern: "${start}$$${end}"
The double $$
escapes the $
so that it is treated as a literal character. The third $
is really part of the named group ${end}
. You can read about this on the MSDN Substitutions page.
I would stick with the above approach. Alternately you can use the Replace
overload that accepts a MatchEvaluator
and concatenate what you need, similar to the following:
jackHas = dollarInsertion.Replace(jackHas,
m => m.Groups["start"].Value + "$" + m.Groups["end"].Value);