title: Writing a regex in JavaScript to match $ variable prefix syntax (like found in Bash scripts)
body: <p>I'm trying to write a regular expression in JavaScript to search a multi-line bash script and extract all the variable names. I can neither seem to figure it out myself nor find a script that does exactly what I need.</p>
  
  <p>I've gotten this far:</p>
  
  <pre><code>var re = /(?:^|\W)\$(\w+)(?!\w)/g;
  var s = "test $test1 testagain$test2 testyetagain $test3 $test4$test5";
  var matches = [];
  while (match = re.exec(s)) {
    matches.push(match[1]);
  }
  </code></pre>
  
  <p>This will give me "test1", "test3", and "test4". But I would also like to get "test2" and "test5".</p>
  
  <p>It would also be great if there were a way I could get "\$" to NOT match if it appears in the string. In other words, is there a way to escape the "$" string in the text so that it is ignored by my regular expression? So in case "\$1.00" appeared in the text, it would <em>not</em> match "1" as the above regex does now.</p>
  
  <p>Thanks in advance for any help or for pointing me in the right direction.</p>
  
  <p>PS This is actually for Action Script 3 but anything that works in JavaScript pre-ES6 should work in AS 3.</p>
  
  <p>PPS The final goal is to replace these matches with variables from a key-value hash.</p>