Match 'regex' in the string - CSharp Language Basics

CSharp examples for Language Basics:Regex

Description

Match 'regex' in the string

Demo Code



using System;//from w  w w  .j  a v a2 s  . co m
using System.Text.RegularExpressions;

class MainClass
{
   static void Main( string[] args )
   {
      string testString = "This is a test for regular expressions or regex or regexp";
      Console.WriteLine( "The test string is\n   \"{0}\"", testString );


      Console.Write( "\nMatch \"regex\" in the test string: " );

      // match 'regex' in the test string
      foreach ( var myMatch in Regex.Matches( testString, "regex" ) )
         Console.Write( "{0} ", myMatch );

      
   }
}

Result


Related Tutorials