private static void TestRegex07()
{
string yourStr = "<group>hello<group/> world ((baby)) ";
string result = Regex.Replace(yourStr, @"<[^>]+>|[()]", string.Empty);
Console.WriteLine(result);
}
{
string yourStr = "<group>hello<group/> world ((baby)) ";
string result = Regex.Replace(yourStr, @"<[^>]+>|[()]", string.Empty);
Console.WriteLine(result);
}
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);
}
}
}
初学正则,想问一下,<[^>]+> 这个是用来匹配<>之间的,为什么要用^>,而不用*?[^>]这个是表示任意的不是>的符号吧?
{
string yourStr = "<group>hello<group/> world ((baby)) ";
string result = Regex.Replace(yourStr, @"<[^>]+>|([()])\1", string.Empty);
Console.WriteLine(result);
}
{2}是重复2次