Advance Search using regular expression

Posted by Madhu.b.rokkam under C# category on | Points: 40 | Views : 2478
string sourceString = "We are Indians, we are Engineers, we are part of DNF ...";
Regex regex = new Regex("are");
MatchCollection matchCol = regex.Matches(sourceString);
foreach (Match match in matchCol)
Console.WriteLine(string.Format("{0} is at {1} position of the string", match.Value.Trim(), match.Index));

are is at 3 position of the string
are is at 19 position of the string
are is at 37 position of the string

Comments or Responses

Login to post response