Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex To Search for Nested Brackets [duplicate]

Tags:

regex

Possible Duplicate:
Can regular expressions be used to match nested patterns?

How do I use regular expressions to search for a pair of opening and closing brackets with arbitrary number of nested brackets inside it e.g.

(...(...(...(...) ...) ...) ...)

Each opening bracket must be matched by a closing bracket. And the number of nested opening-closing pair is arbitrary. Other alphanumeric characters may appear inside the brackets.

like image 214
JavaMan Avatar asked Nov 15 '22 04:11

JavaMan


1 Answers

If you really want to use RegEx to do it(i'm not sure it's the good way), you can loop until this regex \([^\(\)]*\) returns nothing, and for each times you get something you have to remove the result in the initial and loop again...

like image 79
SeeSoft Avatar answered Dec 24 '22 03:12

SeeSoft