I have a regular expression which was working for all my requirement until now, suddenly I got a string which has reserved character like + in c++ and # in C#. Below code work for all my word collection except for c++ and C#
MatchCollection matches= Regex.Matches(@"This program is written in C# We'll delete it after ten days", @"\bC\+\+\b");
foreach(Match m in matches)
{
Console.Write(m.Value);
}
Can any one point out why?
You should use
\B
on the 2nd boundary instead of\b
You can read the following link for more info : http://www.regular-expressions.info/wordboundaries.html