2

I need to fetch the values of a column if it contains special characters other than alphanumeric.

Ex: select name from data;

name

ACD12
A12DD
A_C12
A@CD
AB_M1
123AB

I need to write a regular expression to fetch the following data from the above table:

A_C12
A@CD
AB_M1

1 Answer 1

3

You need an expression that says "Any string that contains at least one non-alpha-numeric character":

SELECT name FROM table1 WHERE name ~ '[^[:alnum:]]'

See: http://sqlfiddle.com/#!12/2edd5/15

I haven't used \W because it's equivalent to [^[:alnum:]_] and you don't want the underscore. See the PostgreSQL docs on regular expressions.

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.