I've seen this topic: How to surround text with brackets using regex? but that's on ruby and I don't know the analog for C# I tried
text = System.Text.RegularExpressions.Regex.Replace(text, ' ' + SpecialWord + ' ', " \"\0\" ", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
but that didn't insert my matched word. So how do I surround my matched word with quotes?
Try using
\b
to match the word boundary, rather than a space.You need to use
$0
instead of\0
too.