0

I have strings in one of my table in which I need to replace some specials characters like ' _ ? ° and square brackets [ ]. When I try this it's working like expected :

SELECT REGEXP_REPLACE('BIG''EAST_?°[]', '[_?°'']', ' ') FROM DUAL;

I get:

BIG EAST   []

Then I add the square brackets in my regex :

SELECT REGEXP_REPLACE('BIG''EAST_?°[]', '[_?°''\[\]]', ' ') FROM DUAL;

I expected this:

BIG EAST

But I get:

BIG'EAST_?° 

How can I properly escape the square brackets in my regex?

1 Answer 1

1

You need to add a * to match multiple occurrences (and in any order) of characters from your pattern

SELECT REGEXP_REPLACE('BIG''EAST_?°[]', '[_?°''\[\]]*', ' ') FROM DUAL;
Sign up to request clarification or add additional context in comments.

4 Comments

It's working perfectly with the sample and on my whole table, thx ! Now, is there a difference, performance side, with your answer and the one of J.Lee, wich is working perfectly too ?
@GuillaumeDeguines, I can't see that answer anymore, looks like it was deleted.
He was suggesting to do : SELECT REGEXP_REPLACE('BIG''EAST_?°[]', '[_?°''\[]|\]', ' ') FROM DUAL;
@GuillaumeDeguines, I don't see any obvious reasons why one would be faster than the other since they are so similar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.