Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Properly select actual non-alphanumeric characters in MySQL column

Tags:

regex

mysql

I have a strange issue with my MySQL REGEXP SELECT query, I'm trying to select rows which contain non-alphanumeric characters. I've tried multiple things and it will match Cyrillic characters, but it does not consider apostrophes and spaces to be non-alphanumeric. Here are the queries I've tried:

SELECT * FROM `table` WHERE `name` REGEXP '^[^[:alnum:]]+$' LIMIT 0,10;

SELECT * FROM `table` WHERE `name` REGEXP '^[^a-z0-9]+$' LIMIT 0,10;

They both return nothing at all now because I've replaced all of the Cyrillic characters, except for spaces and apostrophes. I feel as though I must be doing something incorrectly, because it seems so illogical that MySQL would consider a space and apostrophe to be alphanumeric.

like image 326
simontemplar Avatar asked Jan 22 '15 23:01

simontemplar


1 Answers

Have you tried:

SELECT * FROM table WHERE name REGEXP "[^a-z0-9]+" LIMIT 0,10;
like image 163
Andie2302 Avatar answered Oct 22 '22 01:10

Andie2302