This is a very basic regex question, but I’m not quite sure where I am going wrong.
I am attempting to take an input string such as this:
string exp = @"$a$ + $ab$";
Match the pattern $....$ and replace that value in the original string. For example, I want to substitute the number 1 for $a$ and the number 2 for $ab$, so my final string would look like "1 + 2".
What I have setup is the following function:
private string SubstituteStandardValues(string exp)
{
//Find Std values w/Regex
Match match = Regex.Match(exp, @"/\($.*$\)/s", RegexOptions.IgnoreCase);
if (match.Success)
{
foreach (var m in match.Groups)
{
//Do string replace logic here!
}
}
return exp;
}
My problem is match is always false, which leads me to believe that my regex is incorrect.
Where have I gone astray? Thanks for the help!
Try using this code: