I am trying to build a regex pattern with some parts of pattern retrieved from a database.
For example
string pt= "@\"\\b(" + db.GetPattern + ")\\b\"";
Regex regex = new Regex(pt, RegexOptions.IgnoreCase | RegexOptions.Compiled);
return regex.Replace(input, "*");
Although I tried to escape it, I couldn't get it to work. If I build the pattern manually as
Regex regex = new Regex(@"\b(test|test2)\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);
return regex.Replace(input, "*");
it works fine.