2

I'm trying to use REGEXP_REPLACE to remove all punctuation from a varchar. I'm using the following:

regexp_replace(d.NAME, [.,\/#!$%\^&\*;:{}=\-_`~()])

But it gives me an error, saying:

Statement 1 is not valid. ERROR: syntax error at or near "."

How can I fix this to remove all punctuation?

2
  • 1
    regexp_replace(d.NAME,'[^a-zA-Z]','')? Commented Oct 20, 2016 at 0:39
  • @vkp That would also replace whitespace, numbers, and letters like ñ. That's not acceptable in most cases. Commented Oct 20, 2016 at 0:54

1 Answer 1

8

Firstly, the dash in a character class means a range, except when it's first or last... so put it there:

[.,\/#!$%\^&\*;:{}=\_`~()-]

And, you have to put it in quotes, and most characters don't need escaping:

regexp_replace(d.NAME, '[.,/#!$%^&*;:{}=_`~()-]')
Sign up to request clarification or add additional context in comments.

2 Comments

Worked like a charm, my friend. There don't seem to be many good resources on regex...what's your go-to source?
The site regexr.com is my go-to for any regex testing -- I can't recommend it enough.

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.