title: Postgresql: Invalid regular expression: invalid backreference number
body: <p>I have this regular expression <code>^(?!.*?([aceg]).*?\1)(?!.*?([i])(?:.*?\2){2})[acegi]+$</code> which works as <a href="https://stackoverflow.com/questions/22731889/regular-expression-regex-each-character-can-appear-at-most-as-many-as-given">expected</a> (e.g. in Ruby), but not in PostgreSQL due to "invalid backreference number".</p>
  
  <p>How to solve it and keep given functionality?</p>
  
  <p>Part of the SQL command: <code>WHERE (name ~ '^(?!.*?([aceg]).*?\1)(?!.*?([i])(?:.*?\2){2})[acegi]+$')</code></p>
  
  <p><em>Note: I tried escaping backslash like <code>\\</code> without any error, but PG were returning invalid matches (like "aaa").</em></p>