CSharp examples for Language Basics:Regex
Match a group of at least one word character (lazy)
using System;/* w ww .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 ); // use a lazy quantifier Console.WriteLine("\nMatch a group of at least one word character (lazy)" ); DisplayMatches( testString, @"\w+?" ); } // 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 } }