Regex – replacing square brackets of a string with oracle REGEXP_REPLACE function

oracleregex

I want to replace square brackets in string with REGEXP_REPLACE function. Even I escape these chracters it's not replacing

select regexp_replace('VMI[[DATA]]INFO', '[\[\]]', '_') from dual;

result

VMI[[DATA]]INFO

How can we do this? Am I missing something?

Best Answer

You can do it like this:

select regexp_replace('VMI[[DATA]]INFO', '\[|\]', '_') from dual;

But I don't think that regular expressions are needed here, you can also use TRANSLATE

select translate('VMI[[DATA]]INFO', '[]', '__') from dual;

Here is a sqlfiddle demo