我需要帮助修复下面的正则表达式。我试图将它从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 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);
}
答案 0 :(得分:2)
你的正则表达式在python中也不起作用。
您想使用:
\([a-z\s]+\)
\(
匹配一个左括号,[a-z\s]
允许字母(小写)和任何类型的空格通过\s
(注意 anti -slash)。< / p>
查看(和玩)demo here。