查找括号之间的所有字符与.NET正则表达式括号、字符、正则表达式、NET

2023-09-03 05:53:43 作者:人心对人心多少是真心

我需要的'('和')'字符的所有字符。

I need to get all characters between '(' and ')' chars.

   var str = "dfgdgdfg (aaa.bbb) sfd (c) fdsdfg (   ,ddd   (eee) )";

在这个例子中,我需要3字符串:

In this example, I need to get 3 strings:

(aaa.bbb)
(c)
(    ,ddd   (eee) )

我有什么模式来写?请帮助。

What pattern I have to write? Please, help.

推荐答案

尝试是这样的:

\(([^)] +)\)

编辑:其实这样做的非常的最后一些工作 - 这EX pression没有捕捉到最后一个子正常。我已经CW'd这个答案,这样的人有更多的时间可以人肉出来,使其正常工作。

Actually this does quite work for the last bit - this expression doesn't capture the last substring properly. I have CW'd this answer so that someone with more time can flesh it out to make it work properly.