title: Need Xquery functionality of fn:replace for use with PostgreSQL
body: <p>I am looking for the functionality of the Xquery function <a href="http://www.xqueryfunctions.com/xq/fn_replace.html" rel="nofollow">fn:replace</a> for use with PostgreSQL. Here is the specific XQuery code that needs to be implemented in PostgreSQL:</p>
  
  <pre><code>declare function local:canonical($n as xs:string?) as xs:string? {
    replace(fn:lower-case($n),'[^0-9a-z]','')
    };
  </code></pre>
  
  <p>The intent is to convert upper to lower case and keep only letters and digits.</p>