I have a string that contains values such as "String1...String2..." etc. I am trying to use the Oracle regexp_replace built-in to replace these with "StringA...StringB" and so on. I have done the regex pattern to find the strings and can reference the two parts of the pattern separately as demonstrated by the \1-----\2 in the replace string arguement:
with d as (select '<PatFactors><String1>0</String1><String2>0</String2><String3>0</String3><String4>0</String4><String5>0</String5><String6>0</String6><String7>0</String7><String8>0</String8><String9>0</String9><String10>0</String10><String11>0</String11><String12>0</String12><String13>0</String13><String14>0</String14><String15>0</String15><String16>0</String16><String17>0</String17><String18>0</String18><String19>0</String19><String20>0</String20><String21>0</String21><String22>0</String22><String23>0</String23><String24>0</String24><String25>0</String25><String26>0</String26><String27>0</String27><String28>0</String28><String29>0</String29><String30>0</String30></PatFactors>' as o_requestdata
from dual)
select regexp_replace(o_requestdata, '([Ss]tring)([0-9]+)', '\1-----\2'/*||chr(ascii('A')-1+to_number('\2'))*/ ) from d;
What I would like to do is keep the back reference \1 and then pass \2 into an expression like the one that is commented out. Unfortunately this gets an invalid number error if I uncomment this section.
Does anyone know if it is possible to perform operations on a back reference like this or can you think of any alternatives other than doing a straight replace 30 times for each value?
<PatFactors><String27>0</String27></PatFactors>to be transformed to<PatFactors><String[>0</String[></PatFactors>? The resulting string would be invalid XML.