Here is another way
// using System.Text.RegularExpressions
string inputString = "The cat saw the other cats playing in the back yard.";
string pattern = "cat";
MatchCollection matches = Regex.Matches(inputString, pattern);
foreach (Match match in matches)
Response.Write("Value: " + match.Value + ", Index= " + match.Index + "<BR>");
string inputString = "The cat saw the other cats playing in the back yard.";
string pattern = "cat";
MatchCollection matches = Regex.Matches(inputString, pattern);
foreach (Match match in matches)
Response.Write("Value: " + match.Value + ", Index= " + match.Index + "<BR>");