Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding All Characters Between Parentheses with a .NET Regex

Tags:

c#

.net

regex

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

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

In this example, I need to get 3 strings:

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

What pattern I have to write? Please, help.

like image 774
Laritari Avatar asked Feb 04 '26 18:02

Laritari


1 Answers

Try something like this:

\(([^)]+)\)

Edit: 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.

like image 130
2 revsAndrew Hare Avatar answered Feb 06 '26 09:02

2 revsAndrew Hare