Possible Duplicate:
How to get function parameter names/values dynamically from javascript
I'm currently working on a project in javascript (node.js) that has me trying to get an array of parameter names (NOT values, I do not need arguments) from a function. I'm currently using Function.toString() to get the function string and then running a regex against that to get my parameter list.
Let's take the following SIMPLE example:
var myFunction = function (paramOne, paramTwo) { ... }
Running my regex against this, and then doing some string magic (split, etc) I would expect an array back like this:
paramList = ['paramOne', 'paramTwo']
I have something that works but I'm feeling like it's probably not the best solution given some of the funky characters javascript lets you use for variable names and that javascript will let you define functions on multiple lines.
Here is what I currently have:
function.*[\w\s$]*(\((.*[\w\s,$]*)\))
This gives me my "match" in group 1 and then my param list without parens in group 2, which is cool. Is this really the best way to do what I want? Is there a better regular expression I could use for this? I'm not really looking for something "simpler" but really just something that could catch all possible situations.
Any help would be appreciated, and many thanks in advance!