I'm using the below query to replace the value 2 with 5. My input string will be in the format as shown below. Each value will be delimited with carrot(^) symbol. It's working fine when there is no duplicate value. But with duplicate values it's not working. Please advice.
select regexp_replace('1^2^2222^2','(^|\^)2(\^|$)','\15\2') OUTPUT from dual;
Output:
1^5^2222^5 ( Working Fine as there is no consecutive duplicates at the starting or at the end)
.
select regexp_replace('2^2^2222^2^2','(^|\^)2(\^|$)','\15\2') OUTPUT from dual;
Output:
5^2^^5^2222^5^2(Not working as there is consecutive duplicate at the starting/end)
Please let me know how to correct this?
^symbol is a caret.