I am trying to match a function call using Regex but is not giving on big JS file where nested calls of the same function are inside. For example below is the code in JS file
I am trying to match a function call using Regex but is not giving on big JS file where nested calls of the same function are inside. For example below is the code in JS file
Share
Improve this question
asked Jan 27, 2015 at 9:32
redVredV68411 gold badge99 silver badges2727 bronze badges2
1Why down votes? Mr. Downvoter could you please behave yourself to give explanation for downvote?
– redV
CommentedJan 27, 2015 at 9:35
9I didn't downvote, but it is generally considered a bad idea to use regexes for this kind of job. Particularly because of the nested/recursive nature of the input data. You are better off looking for a library that interprets the JavaScript as exactly that, JavaScript (rather than a huge string) and let's you do what you need to do.
– asontu
CommentedJan 27, 2015 at 10:32
Add a ment
|
1 Answer
1
Reset to default
9
+50
You can use a JS parser like Esprima to do this. This would be the correct and reliable solution rather than a magical regex, in my opinion. Regex's are often hard to maintain and often fail for edge cases. They are very useful in some cases, but this isn't one of them.