I try to implement a conversion a string: "(foo)"
to an Array:[foo]
where foo
is a nested structure.
For instance, we have a string :
"( ('hello' ('world')) (bar) )"
, and this is supposed to be converted to
[['hello', ['world']], [MasterObj['bar']]]
To get started, let's the problem simplified,
"( (foo) (bar) )"
--f--> ["(foo)", "(bar)"]
If I can obtain a function to make this job done, the nested object can be finished recursively.
With a very primitive regex, I could write:
var src = "( (foo) (bar) );"
var src1 = src.match(/\(.*\)/g);
src1 = ['( (foo) (bar) )']
At least, matched parenthesis detected.
var src = "(foo) (bar)";
var src1 =src.match(/\(.*\)/g);
src1 = ['( foo) (bar )'] parenthesis is unmatched.
So, here's my question:
How would you match contents inside of matched parenthesis that is most outside?
Is there a common pattern or regex?
Thanks for your thought.