-2

is there a way to match open and close parentheses? since i am working under bash, it seems that i cannot use local variables and recursive matching.

e.g.

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

edit: the scenario is a little bit different bacause all the parentheses are consecutive

tobeka
  • 17
  • 2
  • 5
    possible duplicate of [Can regular expressions be used to match nested patterns?](http://stackoverflow.com/questions/133601/can-regular-expressions-be-used-to-match-nested-patterns) by way of http://stackoverflow.com/questions/3918681/regexp-to-check-if-parentheses-are-balanced – Kenster Sep 25 '15 at 22:41
  • since all parentheses are consecutive, i thought this may be a property i can make use of – tobeka Sep 25 '15 at 23:07

1 Answers1

0

This is a stretch but if the parentheses are consecutive and the maximum number of them is small, you could do something like ^(?:[\(]{1}[^\(\)]*[\)]{1}|[\(]{2}[^\(\)]*[\)]{2}|[\(]{3}[^\(\)]*[\)]{3}|[\(]{4}[^\(\)]*[\)]{4})$.

Lucas Ross
  • 1,049
  • 8
  • 17