Wednesday 15 September 2010

javascript - split string of chain functions with reg-exp -



javascript - split string of chain functions with reg-exp -

i looked around on stackoverflow not find answer!

anyway, wondering how next in javascript regexp.

i have string

bla().func1($(ele).attr("data")).func2.func3("test")... ;

and want extract func1, func2, func3... given string, have illustration of how that?

bear in mind, function names changes, not func1, func2 ... can load, past, moon ... whatever

repeatedly strip out innermost parenthesized expressions:

class="snippet-code-js lang-js prettyprint-override">var str = 'bla().func1($(ele).attr("data")).func2.func3("test")... '; var look = /\([^(]*?\)/g; while (expression.test(str)) { str = str.replace(expression, ''); } document.write(str.split('.').slice(1).join(' '));

however, shouldn't (why want to?). js should parsed by, well, js parsers. instance, above fail miserably if there's string literal containing parenthesis. should parse using esprima , analyze resulting parse tree.

javascript regex parsing

No comments:

Post a Comment