Why does the second statement fail?
works
Regex.Replace("zz WHERE zz", "where", "yy", RegexOptions.IgnoreCase | RegexOptions.Singleline);
does not
Regex.Replace("zz WHERE zz", "\bwhere\b", "yy", RegexOptions.IgnoreCase | RegexOptions.Singleline);
This works to but replaces the space which i do not want to do
Regex.Replace("zz WHERE zz", " where ", "yy", RegexOptions.IgnoreCase | RegexOptions.Singleline);
Because
\bis the backspace control character (U+0008). The backslashes themselves there don’t even get to the regular expression.To use it as intended in a regular expression you need to either double-escape (escape the backslashes for C#’s string so they are normal backslashes for the regex):
or use a verbatim string literal: