using System.Text.RegularExpressions;
public static void Main()
var str = "I have asked the question in StackOverflow. Therefore i can expect answer here.";
var numMatches = Regex.Matches(str.ToUpper(), "THE")
(match.Index == 0 || str[match.Index - 1] == ' ') &&
(match.Index + match.Length == str.Length ||
str[match.Index + match.Length].ToString(),
Console.WriteLine(numMatches);