I discussed this question C #, Regex.Match whole words
It says that the word "\ bpattern \ b" is used for the whole word . This is great for matching the whole word without any special characters, since it is only for text characters!
I need an expression to match words with special characters. My code is as follows
class Program { static void Main(string[] args) { string str = Regex.Escape("Hi temp% dkfsfdf hi"); string pattern = Regex.Escape("temp%"); var matches = Regex.Matches(str, "\\b" + pattern + "\\b" , RegexOptions.IgnoreCase); int count = matches.Count; } }
But it fails due to%. Do we have a workaround for this? There may be other special characters such as "space", "(',')", etc.
Guruc
source share