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]*)\)(?!\]) 
not sure looking looks like!
new edit:
(?:[^[]|^)?\((.*)\)(?!\]) 
edit 3:
(?:[^[]|^)\((.*?)\)(?:(?!\])) 
Comments
Post a Comment