How to escape a regexp_replace in Oracle?
<p>I am creating a small replaceParam function for Strings and wanted to be able to escape a replacement, e. g.</p>

<pre><code>select regexp_replace('%ABC# %ABC#','%ABC#', 'XXX')
from dual;
</code></pre>

<p>leads to</p>

<pre><code>XXX XXX
</code></pre>

<p>BUT I want to be able to escape the replacment, e. g. by preceding a \ in front of a string, that would be otherwise replaced.</p>

<pre><code>select regexp_replace('%ABC# \%ABC#','&lt;themagicregexp&gt;', 'XXX')
from dual;
</code></pre>

<p>should lead to</p>

<pre><code>XXX \%ABC#
</code></pre>

<p>I tried the non-matching character list, but this doesn't work.</p>

<pre><code>select regexp_replace('%ABC#abc\%ABC#','&lt;themagicregexp&gt;', 'XXX')
from dual;
</code></pre>

<p>should lead to</p>

<pre><code>XXXabc\%ABC#
</code></pre>

<p>In addition because someone mentioned it: I can't go with word boundaries, since this should work also:</p>

<pre><code>yoyo%ABC#yoyo
</code></pre>

<p>I have the feeling this can be done in one regexp, but I just don't see it?</p>