C#正则表达式范例replace

来源:互联网 发布:淘宝悬浮导航怎么做 编辑:程序博客网 时间:2024/05/21 17:13
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Text.RegularExpressions;namespace ConsoleApplication2{    class Program    {        static void Main(string[] args)        {            string str = " /* --------------------- hello-hi ----------------------- */ ";                        Regex r = new Regex("/\\* -{2,}");            if (r.IsMatch(str))                str = r.Replace(str, "");            r = new Regex("-{2,} \\*/");            if (r.IsMatch(str))                str = r.Replace(str, "");            Console.WriteLine(str.Trim());        }    }}