Subscribe via RSS ... Subscribe via e-mail ... Follow me on Twitter ... Follow me on Facebook ...




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();
      }
    }
  }
}


one response to “C# – Finding substrings with regular expressions”

  1. Churro says:

    Thank you! That’s exactly the piece of code I needed right now… :)

Leave a comment


But please respect the commenting rules. Critizism is appreciated and also general comments of course. If you're rude, I have to delete your comment. Also use your personal/nick name but avoid using business names. Have fun and thanks for participating the discussion.