1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | using System; using System.Text.RegularExpressions; namespace RegexTest { public class RegexTest { static void Main() { string lText = "Kevin David Mitnick is a computer " + "security consultant and author. In" + " the late 20th century, he was " + "convicted of various computer- and" + " communications-related crimes. At" + " the time of his arrest, he was " + "the most-wanted computer criminal " + "in the United States"; Regex lRegex = new Regex("computer", RegexOptions.IgnoreCase); Match lMatches = lRegex.Match(lText); while (lMatches.Success) { Console.WriteLine("\"{0}\" found, offset {1}" , lMatches.Value, lMatches.Index); lMatches = lMatches.NextMatch(); } } } } |
Thank you! That’s exactly the piece of code I needed right now… :)