-3

I have a string in a table column delimited by '+'. I need to remove the duplicates.

Illustration :

My data:

a+a+a+b+b+c+c

Expectation:

a+b+c

I tried with REGEXP_REPLACE but not able to escape the + character as it is reserved.

I am successful with comma separated value but need help with + or ? separated values.

Working Code with comma separated value:

SELECT REGEXP_REPLACE ('a,a,a,b,b,c,c', '([^,]+)(,\1)+', '\1') FROM DUAL;

2 Answers2

1

If you need to use a reserved character as its normal value you need to escape it with a backslash. This works for all reserved characters.

\

You can modify your existing code by replacing each comma in the regex with...

\+

For example:

SELECT REGEXP_REPLACE('a+a+a+b+b+c+c', '([^\+]+)(\+\1)+', '\1') FROM DUAL;
Matthew Hart
  • 359
  • 2
  • 10
0

just escape the +:

 SELECT REGEXP_REPLACE ('a+a+a+b+b+c+c', '([^\+]+)(\+\1)+', '\1') FROM DUAL;
marco
  • 671
  • 6
  • 22