title: PostgreSQL regex_replace
body: <p>I want to convert a string <code>___abc_[_]xyz</code> to <code>...abc.\_xyz</code> using regular expression.</p>
  
  <p>Is it possible to convert <code>_</code> and <code>[_]</code> into <code>.</code> and <code>\_</code> respectively in the same query?</p>
  
  <p>This is what I have done so far:</p>
  
  <pre><code>SELECT regexp_replace('___abc_[_]xyz','\[(.)\]','\\\1','g');
  </code></pre>
  
  <p>and </p>
  
  <pre><code>SELECT regexp_replace('___abc_[_]xyz','\[_\]','\_','g');
  </code></pre>
  
  <p>The Result of both queries is: <code>___abc_\_xyz</code></p>