I'm looking for a way to use the length of a match group in the replace expression with the c# regex.replace function.
That is, what can I replace ??? with in the following example to get the desired output shown below?
Example:
val = Regex.Replace("xxx", @"(?<exes>x{1,6})", "${exes} - ???");
Desired output
X - 3
Note: This is an extremely contrived/simplified example to demonstrate the question. I realize for this example a regular expression is not the ideal way of doing this. Just trust me that the real world application of the answer is part of a more complex problem that does necessitate the use of a RegEx replace here.