private static void TestRegex07()
{
    string yourStr = "<group>hello<group/> world ((baby)) ";
    string result = Regex.Replace(yourStr, @"<[^>]+>|[()]", string.Empty);
    Console.WriteLine(result);
}

解决方案 »

  1.   

    string result = Regex.Replace("<group>hello<group/> world ((baby))",@"(<[^>]*>|\(|\))*",String.Empty);result 的值就为 “hello world baby”
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Collections;
    using System.Xml.Linq;namespace ConsoleCSharp
    {
          class Program
        {        static void Main(string[] args)
            {
                string yourStr = "<group>hello<group/> world ((baby)) <people>xxxx<people/>";
                string result = Regex.Replace(yourStr, @"<[^>]*>|\(|\)", string.Empty);
                Console.WriteLine(result);
            }
        }
    }
      

  3.   

    <[^>]+>|[()]换成<[*]+>|[()]也可以的。
    初学正则,想问一下,<[^>]+> 这个是用来匹配<>之间的,为什么要用^>,而不用*?[^>]这个是表示任意的不是>的符号吧?
      

  4.   

    <后面必然要跟个>,你可以用.*?来找。但是非贪婪匹配会每次都要回溯,效率不高。限定一个规则,使用贪婪模式,速度会快,避免回溯。你那样修改了肯定不行。
      

  5.   

    我是楼主我还想问一下,如果我只想去掉两个括号的括号((或))而如果字符串中出现如(abc)只有一个括号则不去掉括号怎么写?谢谢。
      

  6.   

    <group>hello<group/> world ((baby)) 使其变成 hello world baby <[^>]*>|\(\(|\)\)
      

  7.   

    <[^>]*>|[()]{2,} 我会了,这样也成吧。
      

  8.   

    private static void TestRegex07()
    {
        string yourStr = "<group>hello<group/> world ((baby)) ";
        string result = Regex.Replace(yourStr, @"<[^>]+>|([()])\1", string.Empty);
        Console.WriteLine(result);
    }
      

  9.   

    <[^>]*>|[()]{2,} [\(\)]   ()需要加上\转义{2,}是重复2或2次以上
    {2}是重复2次