Q:

How do I exclude a regex value in a replace

I have a regex expression which searches for strings using a Prefix and a Suffix.  In it's simplest form \$\$\w+\$\$ will find $$My_Name$$ (in this case the Prefix and Suffix are both equal to $$) Another example would be \[\#\w+\#\] to match [#My_Name#]. 
The Prefix and Suffix will always be a specific string of 0 to n characters which I can always safely escape for a direct character match. 
I extract the Matches in my C# code so I can work with them but obviously my match contains $$My_Name$$ but what I want is to simply get the inner string between the Suffix and Prefix: My_Name. 
How do I exclude the Prefix and Suffix from the result? 

A:

Change your REGEX to \$\$(\w+)\$\$ and use $1 to get the matching (inner) string. 
For example
string pattern = @"\$\$(\w+)\$\$";
string input = "$$My_Name$$";
Regex rgx = new Regex(pattern);
Match result = rgx. Match(input);
Console. WriteLine(result. Groups[1]);

Outputs: "My Name"
P.S - There's no need to use explicitly typed local variables, but I just wanted the types to be clear.