I am having trouble doing the following search and replace:
// Consider this string - Note that it may be much more complicated, with many more matches
string output = "\"$type\": \"SomeType\",";
// The variable to search and replace - In this case is set to "SomeType"
string myType = "SomeType";
// The non-working regex
output = Regex.Replace(output, @"\"\$type\"\:\s\"" + myType + @"\",", "NewType");
I would expect the following output:
"$type": "NewType",
instead of:
"$type": "SomeType",
I think there are 2 problems here, but I cannot figure out the syntax. One is the use of the string "type", the other one is that I am not using capture groups so that only myType gets replaced by "NewType" in the output string.