Just for clarity before I start my ask, I have sample C-code that I'm trying to modify with C# regular expressions. I'm not asking a question about C, I'm just using C# to automatically generate a C-file using regexes.
I'm trying to write a regex that'll replace a substring between two matching strings (tags). I followed along with this question, but I think I'm failing because my "tags" take the form of C-style block comments (which have backslashes and asterisks which are special characters in regex). Ultimately this will be used to automate the replacement of certain values in a C source file.
This is an example of some of my C-code:
SetKeyString("modelNumber", /* #ModelNumber#*/ config.modelNumber /*#ModelNumber#*/);
config.maxKV = /*#MaxKV#*/ 88.88 /*#MaxKV#*/;
I want to replace config.modelNumber and 88.88 with new values obtained externally from an XML file.
Suppose the data from my XML file is:
<ModelNumber>ABCDE</ModelNumber>
<MaxKV>99.99</MaxKV>
The resulting C-code should be
SetKeyString("modelNumber", /*#ModelNumber#*/ ABCDE /*#ModelNumber#*/);
config.maxKV = /*#MaxKV#*/ 99.99 /*#MaxKV#*/;
This is the Regex I'm currently using to attempt (and miserably fail) at this.
string x = Regex.Replace(mainLines[i], @String.Format(@"?<=/*#{0}#*/)(\w+?)(?=/*#{0}#*/)", property.Name), "middle");
mainLines are the individual lines of my C-file and property.Name is the name of the XML tag: ModelNumber or MaxKV (without any characters on the ends).
Update - Additional examples
During further testing of proposed solutions failure edge cases were found so here are additional example inputs which caused failures:
config.kvRampRate = /*#KVRampRate#*/ (10.0 / config.maxKV * 4095) / 12.124567719929887 /*#KVRampRate#*/;
config.maRampRate = /*#MARampRate#*/ 1.0/config.maxMA * 4095 / /*mARampRate-->*/87.80017152658661 /*#MARampRate#*/;

\*. You don't want a sequence of zero or more slashes, which is what you're trying to match:/*. You want a slash followed by an asterisk:/\*.