regex for searching balanced parentheses -


is there way match open , close parentheses? since working under bash, seems cannot use local variables , recursive matching.

e.g.

(((((123))))) # shall matched ((123)        # shall not. 

edit: scenario little bit different bacause parentheses consecutive

this stretch if parentheses consecutive , maximum number of them small, ^(?:[\(]{1}[^\(\)]*[\)]{1}|[\(]{2}[^\(\)]*[\)]{2}|[\(]{3}[^\(\)]*[\)]{3}|[\(]{4}[^\(\)]*[\)]{4})$.


Comments