Refactor variable names in JavaScript code
Ruby, 134 (113?) characters
*c,o,n=*$&lt;;puts (c*?\n).gsub(/('|&quot;)((\\?+.)*?)\1|\/\*[\s\S]*?\*\/|\/\/.*|\/(\[\g&lt;2&gt;\]|\g&lt;2&gt;)+?\/\w*|([\w$]+)/){$5==o.chop&amp;&amp;n.chop||$&amp;}

Unicode is not supported. If Unicode identifiers are to be supported, replace \w with [[:word:]]  and [\w$] with ([[:word:]]|\$) (and adjust the backreferences).
If unescaped slashes inside regexp literals (such as /[/]/) don't need to be supported, we can handle them together with string literals (116 characters). This also gives us string flags:
*c,o,n=*$&lt;;puts (c*?\n).gsub(/\/\*[\s\S]*?\*\/|\/\/.*|('|&quot;|\/)((\\?+.)*?)\1\w*|([\w$]+)/){$4==o.chop&amp;&amp;n.chop||$&amp;}

Ungolfed version:
*code, old, new = *$&lt;

puts code.join(&quot;\n&quot;).gsub (/
     ('|&quot;)((\\?+.)*?)\1           #strings
   | \/\*[\s\S]*?\*\/             #multiline comments
   | \/\/.*                       #single-line comments
   | \/(\[\g&lt;2&gt;\]|\g&lt;2&gt;)+?\/\w*   #regexes
   | ([\w$]+)                     #identifiers and keywords
/x){
  if $5 == old.chop then new.chop else $&amp; end
}