agaggi agaggi - 2 months ago 11
MySQL Question

php mysql search all special characters

I cant figure out how to search for all special characters in mysql databse in single query.

For eg. search mysql and return the row whose column contains any of the special character like ",'#~;%*{ , etc. (means if some field have characters except 0-9, a-z, A-Z).

sample query type i want ---

SELECT * FROM mytable where column = 'PATTERN TO DETECT ALL SPECIAL CHARACTERS';


please also help with another query if i want to exclude some special chareacters like & ( ) . - from being searched.

Answer

Your query would like this, check the regex

SELECT * 
FROM mytable 
WHERE column regexp '[^a-zA-Z0-9]'

And the second query would be similar

SELECT * 
FROM mytable 
WHERE column regexp '[^a-zA-Z0-9\&]'

\ + character to ignore