0

I need to identify and replace all the control characters in a column with '' I tried using following query.

 SELECT description, REGEXP_REPLACE(description, '[![:cntrl:]]', '') from table1;

It removes all the control characters along with the new line character. I need to sustain the new line character. I tried using something like following.

 REGEXP_REPLACE(description, '[![:cntrl:]'||CHR(10)||CHR(13)||']', '')

But it didn't work. I would appreciate any help in right direction. Thanks in advance.

1
  • can you share more information or the sample data vs expected data ? Commented Oct 16, 2018 at 12:35

1 Answer 1

4

:cntrl: is the opposite of :print:, so you could negate the combination of that plus the control character(s) you want to keep:

regexp_replace(description, '[^[:print:]'||chr(10)||']', null)

or possibly, based on your attempt (but not needed if you did only mean 'new line'):

regexp_replace(description, '[^[:print:]'||chr(10)||chr(13)||']', null)

The negation is done by ^, not !. Your original code was removing any control characters or the actual character !, which probably wasn't quite what you meant.

Sign up to request clarification or add additional context in comments.

Comments

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.