Match a sentence - CSharp Language Basics

CSharp examples for Language Basics:Regex

Description

Match a sentence

Demo Code



using System;//from  w  w  w. ja va 2s . c  om
using System.Text.RegularExpressions;

class RegexMatches
{
   static void Main( string[] args )
   {
      // create a regular expression
      Regex expression = new Regex( @"J.*\d[\d-[4]]-\d\d-\d\d" );

      string testString =
         "Mary's Birthday is 05-12-75\n" +
         "Jay's Birthday is 11-04-2000\n" +
         "John's Birthday is 04-28-73\n" +
         "Joe's Birthday is 12-17-1977";

      // display all matches to the regular expression
      foreach ( var regexMatch in expression.Matches( testString ) )
         Console.WriteLine( regexMatch );
   }
}

Result


Related Tutorials