javascript - Regex match parenthesis that are not within square braces -


i'm trying determine expression contains parentheses (...), (...) not within square braces. use parsing , processing simple lisp style expressions.

i've adapted following working expression used split string on space characters not within square brackets, can't seem achieve same effect above case.

the expression using:

/(\[.*?\]|(\(.*\)+))/g 

here list of example expressions desired output haspair function.

 - (+ 2 2) -> true  - (+ 2 (- 4 2)) -> true  - [(+ 2 2)] -> false   - [(def (+ 2 2)] -> false  - (defn add [+ 2 2]) -> true  - def add [(+ 2 2)] -> false  - (defn add x y [(+ x y]) -> true 

i'm missing obvious, can't see is.

(the expressions balanced, if makes difference)

(?:[^[]|^)\(([\w]*)\)(?!\]) 

regular expression visualization

edit live on debuggex

not sure looking looks like!

new edit:

(?:[^[]|^)?\((.*)\)(?!\]) 

regular expression visualization

edit live on debuggex

edit 3:

(?:[^[]|^)\((.*?)\)(?:(?!\])) 

regular expression visualization

edit live on debuggex


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -