use the . (dot) metacharacter to match any character - CSharp Language Basics

CSharp examples for Language Basics:Regex

Description

use the . (dot) metacharacter to match any character

Demo Code



using System;//w  w  w .  j a  v a2  s . com
using System.Text.RegularExpressions;

class MainClass
{
   static void Main( string[] args )
   {
      string testString = "abc, DEF, 123";
      Console.WriteLine( "The test string is: \"{0}\"", testString );

      // use the . (dot) metacharacter to match any character
      Console.WriteLine( "\nMatch a group of any characters" );
      DisplayMatches( testString, ".*" );
   }

   // display the matches to a regular expression
   private static void DisplayMatches( string input, string expression )
   {
      foreach ( var regexMatch in Regex.Matches( input, expression ) )
         Console.Write( "{0} ", regexMatch );

      Console.WriteLine(); // move to the next line
   }  
}

Result


Related Tutorials