Regex C#正则表达式匹配整个括号内容
我需要帮助修复下面的正则表达式。我试图将它从Python重写为C#,但C#显示空的m.value。谢谢 在Python中,它运行良好,并显示括号和内部内容: Python代码:Regex C#正则表达式匹配整个括号内容,regex,Regex,我需要帮助修复下面的正则表达式。我试图将它从Python重写为C#,但C#显示空的m.value。谢谢 在Python中,它运行良好,并显示括号和内部内容: Python代码: r1="(dog apple text) (grape cushion cat)" a=re.findall("[(]+[/s]+[a-z]+[)]+",r1) print(a[:]) //Conent gives me (dog apple text) (grape cushion cat) , so if I wi
r1="(dog apple text) (grape cushion cat)"
a=re.findall("[(]+[/s]+[a-z]+[)]+",r1)
print(a[:])
//Conent gives me (dog apple text) (grape cushion cat) , so if I will call print(a[0]) it will give me (dog apple text)
String r1="(dog apple text) (grape cushion cat)"
String pat=@"[(]+[/s]+[a-z]+[)]+";
foreach (Match m in Regex.Matches(irregv, pat2))
{
Console.WriteLine("'{0}'", m.Value);
}
您的正则表达式在python中也不起作用 您要使用:
\([a-z\s]+\)
\(
匹配一个左括号,[a-z\s]
允许字母(小写)和任何类型的空格通过\s
(注意反斜杠)
查看(并玩)。
/s
应该是\s
,但即使这样,您的表达式也会匹配(((((((((((((((())hello))
之类的内容,而不是您的示例中的任何内容。您最好从一些教程开始—有很多很好的示例信息。也值得查看。