title: Convert regexp from php to javascript (lookback assertion)
body: <p>I have this regexp to replace embedded RGB colors {rrggbb} (always exactly 6 characters enclosed in curly brackets) into html span tags:
  <code>{([a-fA-F0-9]+)}((?&gt;[^{]*{?(?!(?1)}))*)</code></p>
  
  <p>It was used like this:</p>
  
  <p><code>preg_replace('~{([a-fA-F0-9]+)}((?&gt;[^{]*{?(?!(?1)}))*)~',
          '&lt;span style="color: #$1"&gt;$2&lt;/span&gt;', $text);</code></p>
  
  <p>It worked well with preg_replace in php, but when trying to use it in javascript I'm getting a syntax error (? The preceding token is not quantifiable)</p>
  
  <p>How can I make it work in javascript?</p>
  
  <p>Note I have another regexp: <code>{([a-fA-F0-9]{6})\}([^\{]+)</code> which works, however if I do something like this: <code>{ff0000}red text {some text that isn't a color} {00ff00}blue text</code> I'm getting an output of: <code>&lt;span style="color: #ff0000"&gt;red text &lt;/span&gt;{some text that isn't a color} &lt;span style="color: #00ff00"&gt;blue text&lt;/span&gt;</code>, note that <code>{some text that isn't a color}</code> isn't wrapped in any <code>span</code> tag, while it still should be in the previous tag. I dont know how to fix it though.</p>