title: Lua gsub expression to rename variables in a Lua script
body: <p>I would like a gsub pattern to rename variables in a Lua script. Say I wanted to rename <code>x</code> to <code>y</code>.</p>
  <p><code>scr = scr:gsub(...,'y')</code></p>
  <p>Where <code>...</code> would find instances of x that are not beside any underscore, letter, or number.</p>
  <p>EDIT: Here's an attempt</p>
  <pre class="lang-lua prettyprint-override"><code>-- should be replaced?
  --  yes   yes   no      no      yes   yes  yes    yes   no    no     no     yes
  s = 'unc unc function FUNCTION :unc: .unc. -unc- =unc=  unc1 unc_ \' unc\' unc'
  print(s:gsub('([%A?%-?])(unc)([%W?%-?])', '%1XXX%3'))
  -- need to fix the start or beginning of string
  --    could easily pad the string with a space then remove
  -- also missing underscores and strings (ie dont replace between quotes) though..
  -- tried ^_? (not 0 or 1 underscore) but it didn't work
  </code></pre>
  <p><code>&gt; unc XXX function FUNCTION :XXX: .XXX. -XXX- =XXX=  unc1 XXX_ ' XXX' unc</code></p>