title: Scite Lua - escaping right bracket in regex?
body: <p>Bumped into a somewhat weird problem... I want to turn the string:</p>
  
  <p>a\left(b_{d}\right)</p>
  
  <p>into </p>
  
  <p>a \left( b_{d} \right)</p>
  
  <p>in Scite using a Lua script. </p>
  
  <p>So, I made the following Lua script for Scite: </p>
  
  <hr>
  
  <pre><code>function SpaceTexEquations()
    editor:BeginUndoAction()
      local sel = editor:GetSelText()
  
      local cln3 = string.gsub(sel, "\\left(", " \\left( ")
      local cln4 = string.gsub(cln3, "\\right)", " \\right) ")
  
      editor:ReplaceSel(cln4)
    editor:EndUndoAction()
  end
  </code></pre>
  
  <hr>
  
  <p>The cln3 line works fine, however, cln4 crashes with:</p>
  
  <pre><code> /home/user/sciteLuaFunctions.lua:49: invalid pattern capture
   &gt;Lua: error occurred while processing command
  </code></pre>
  
  <p>I think this is because bracket characters () are reserved characters in Lua; but then, how come the cln3 line works without escaping? By the way I also tried:</p>
  
  <pre><code>-- using backslash \ as escape char:
  local cln4 = string.gsub(cln3, "\\right\)", " \\right) ") -- crashes all the same
  
  -- using percentage sign % as escape chare
  local cln4 = string.gsub(cln3, "\\right%)", " \\right) ") -- does not crash, but does not match either
  </code></pre>
  
  <p>Could anyone tell me what would be the correct way to do this? </p>
  
  <p>Thanks, </p>
  
  <p>Cheers!</p>