CSharp examples for Language Basics:Regex
replace the first three digits with the word "digit"
using System;//from w w w . j a v a 2s. co m using System.Text.RegularExpressions; class MainClass { static void Main( string[] args ) { string testString2 = "1, 2, 3, 4, 5, 6, 7, 8"; Regex testRegex1 = new Regex( @"\d" ); Console.WriteLine( "\nSecond test string: {0}", testString2 ); // replace the first three digits with the word "digit" Console.WriteLine( "Replace first 3 digits by \"digit\": {0}", testRegex1.Replace( testString2, "digit", 3 ) ); } }