perl - Regex to capture everything inside ( ... ) but also handle cases where ( is used inside -
i trying capture using perl regex data found inside this:
variable_myname(variable_data); so used:
variable_([a-za-z_]+)(\s+)?\((.*?)\) this allowed me capture myname of variable (which prefixed variable_) data inside (...).
however, doesn't work if user uses (allowed) syntax of:
variable_oneexp("this value ( ... ) "); which because of ", ( , ) should ignored.
same behavior should handled if ' used:
variable_twoexp('this value ( ... ) '); finally, behavior should supported:
variable_threeexp('this value ' + ' string '); though, don't think last example makes difference regex.
some pointers/assistance appreciated.
you use negated class instead of lazy .*?, use alternation match between single/double quotes:
variable_([a-za-z_]+)\s*\(((?:'[^']+'|"[^"]+"|[^()])+)\) i removed capture group around \s+, , turned \s* since don't believe need spaces in capture group. revert if need it.
Comments
Post a Comment