match anything that isn't in the range 'a' to 'f' - CSharp Language Basics

CSharp examples for Language Basics:Regex

Description

match anything that isn't in the range 'a' to 'f'

Demo Code



using System;/*from   w w  w  . jav a  2  s. c o  m*/
using System.Text.RegularExpressions;

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

      // match anything that isn't in the range 'a' to 'f'
      Console.WriteLine( "\nMatch anything not from 'a' - 'f'" );
      DisplayMatches( testString, "[^a-f]" );
   }


   // 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