C# 正则表达式
Console.ReadKey(); } }}当上面的代码被编译和执行时,它会产生下列结果:Matching words start with 'm' and ends with 'e':The Expression: \bm\S*e\bmakemazemanagemeasure实例 3下面的实例替换掉多余的空格:using System;using System.Text.RegularExpressions;namespace RegExApplication{ class Program { static void Main(string[] args) { string input = "Hello World "; string pattern = "\\s+"; string replacement = " "; Regex rgx = new Regex(pattern); string result = rgx.Replace(input, replacement); Console.WriteLine("Original String: {0}", input); Console.WriteLine("Replacement String: {0}", result); Console.ReadKey(); } }}当上面的代码被编译和执行时,它会产生下列结果:Original String: Hello World Replacement String: Hello World
C# 正则表达式