I was using StringBuilder.Replace() to change some "keywords" to my own methods, but since it doesn't match the whole word I need to find a way to replace it correctly.
string example = "Hey $name! Welcome to $namewebsite!";
StringBuilder sb = new StringBuilder(example);
sb.Replace("$name", "getName()");
sb.Replace("$namewebsite", "getWebSiteName()");
return sb;
Above the output will be "Hey getName()!, Welcome to getName()website!", so I'm trying to use RegEx to match the whole word.
string example = "Hey $name! Welcome to $namewebsite!";
example = Regex.Replace(example, "\b$name\b", "getName()");
example = Regex.Replace(example, "\b$namewebsite\b", "getWebSiteName()");
return example;
But since the "keyword" has the symbol "$" it doesn't work, at least that's what I think, because it doesn't replace any of the "keywords".
Of course it's just a small example of my code, I have like 30+ keywords starting with "$" to replace to methods names.
\$?$to escape it, i.e. use"\$". Or alternativelyRegex.Escape("$name")