How to replace captured group with evaluated expression (adding an integer value to capture group)
<p>I need to convert some strings with this format:</p>
<p><em>B12F34</em></p>
<p>to something like that:</p>
<p><em>Building 12 - Floor 34</em></p>
<p>but I have to add a value, say 10, to the second capture group so the new string would be as:</p>
<p><em>Building 12 - Floor <strong>44</strong></em></p>
<p>I can use this postgres sentence to get almost everything done, but I don't know how to add the value to the second capture group.</p>
<pre><code>SELECT regexp_replace('B12F34', 'B(\d+)F(\d+)', 'Building \1 - Floor \2', 'g');
</code></pre>
<p>I have been searching for a way to add a value to \2 but all I have found is that I can use 'E'-modifier, and then \1 and \2 need to be \\1 and \\2:</p>
<pre><code>SELECT regexp_replace('B12F34', 'B(\d+)F(\d+)', E'Building \\1 - Floor \\2', 'g')
</code></pre>
<p>I need some sentence like this one:</p>
<pre><code>SELECT regexp_replace('B12F34', 'B(\d+)F(\d+)', E'Building \\1 - Floor \\2+10', 'g')
</code></pre>
<p>to get ........ <em>Floor <strong>44</strong></em>     instead of ........ <em>Floor <strong>34+10</strong></em></p>