Pages

Showing posts with label RegexOptions.IgnoreCase. Show all posts
Showing posts with label RegexOptions.IgnoreCase. Show all posts

Thursday, September 26, 2013

REGEX to match the exact word in the string, ignoring case.



 string keyword="ankit";
 string str="my name is ankit";


 if (Regex.Match(str.Trim().ToLower(), @"\b" + keyword.Trim().ToLower() + @"\b", RegexOptions.Singleline | RegexOptions.IgnoreCase).Success)
{
      // if matches
}
else
{
     // if not matches
} 



Here, in 'if' condition "Success" is used to the condition is true or not, just like "==true"