标签:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; namespace _17._5正则表达式的替换 { class Program { static void Main(string[] args) { string input = "Welcome to ***ww****w*********************"; string pattern = @"\bw{3}\.\w+\.(com|net|org)\b"; string replacment ="\n"+@"http://$&"; Console.WriteLine("替换前的字符串"+input); Console.WriteLine("替换后的字符串"); Console.WriteLine(Regex.Replace(input,pattern,replacment)); Console.WriteLine("替换后的字符串1:"+(Regex.Replace(input,pattern,replacment,RegexOptions.IgnoreCase)).ToLower()); Console.WriteLine("替换后的字符串2:"+Regex.Replace(input,"www","\n"+@"http://www.",RegexOptions.IgnoreCase)); Regex myregex = new Regex(pattern,RegexOptions.IgnoreCase); string result = myregex.Replace(input, replacment); Console.WriteLine("替换后的字符串3:"+result.ToLower()); Console.ReadKey(); } } }
标签:
原文地址:http://www.cnblogs.com/zqyo2000z/p/5515883.html