title: Regular Expression to get parameter list from function definition
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1007981/how-to-get-function-parameter-names-values-dynamically-from-javascript">How to get function parameter names/values dynamically from javascript</a>  </p>
  </blockquote>
  
  
  
  <p>I'm currently working on a project in javascript (node.js) that has me trying to get an array of parameter <strong>names</strong> (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. </p>
  
  <p>Let's take the following SIMPLE example:</p>
  
  <pre><code>var myFunction = function (paramOne, paramTwo) { ... }
  </code></pre>
  
  <p>Running my regex against this, and then doing some string magic (split, etc) I would expect an array back like this:</p>
  
  <pre><code>paramList = ['paramOne', 'paramTwo']
  </code></pre>
  
  <p>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. </p>
  
  <p>Here is what I currently have:</p>
  
  <pre><code>function.*[\w\s$]*(\((.*[\w\s,$]*)\))
  </code></pre>
  
  <p>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.</p>
  
  <p>Any help would be appreciated, and many thanks in advance!</p>