Question

My problem is that I need to remove all invalid characters from a column, but the dash and brackets characters are valid ones.

as so far my sql is:

SELECT REGEXP_REPLACE(column_name, '[^][-0-9a-z]' , '') FROM table_name;

but this doesn't include the dash character.

and:

SELECT REGEXP_REPLACE(column_name, '[^-][0-9a-z]' , '') FROM table_name;

this isn't good either.

Was it helpful?

Solution

There are 2 solutions for this:

1, use one of them at start and other at the end of the Matching Character List:

SELECT REGEXP_REPLACE(column_name, '[^][0-9a-z-]' , '') FROM table_name;

2, using the POSIX Collating Element Operator [.character.]:

SELECT REGEXP_REPLACE(column_name, '[^[.].][.[.][.-.]0-9a-z]' , '') FROM table_name;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top