Is there a regular expression that matches JavaScript functions?
Like
function abc(var1, var2){
..
}
// and
abc : function(var1, var2){
...
},
I know this question is 5 years old, but contrary to what everyone else has said, i have actually concocted a quite effective pattern for doing as you have asked. Albeit, quite complex, I have used this several times in my own projects and I've yet to have a hiccup... wish I had seen this question much sooner. Hope this helps (If not for you, hopefully for those who are searching for a similar solution)
function\s*([A-z0-9]+)?\s*\((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\)\s*\{(?:[^}{]+|\{(?:[^}{]+|\{[^}{]*\})*\})*\}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With