Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
Thanks, its working fine –  Ram Ch Nov 5 '12 at 11:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.