Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php mysql query first letter !=[a-z]

Tags:

php

mysql

SELECT * FROM dbname WHERE text = 'a%' 
(this can get all the `text` fields which begin with the letter "a".)

But how to get the fields where the first letter !=[a-z]?

for example:

\"hello\"  // this first letter begin as \ not range in a-z
いけ  // also first letter not begin range in a-z
... 
may also have a white space as the first character.

So how can you use php mysql query to get all these kinds of results where the first letter !=[a-z]?

like image 475
yuli chika Avatar asked Aug 27 '11 22:08

yuli chika


1 Answers

Try this:

SELECT * FROM dbname WHERE text REGEXP '^[^a-zA-Z]';

That is if you want it to be case insensitive (uppercase or lowercase). If you want to allow uppercase letters A-Z then just use:

SELECT * FROM dbname WHERE text REGEXP '^[^a-z]';

Essentially the regular expression says match any string that doesn't have letters a-z at the beginning of the string.

like image 200
JJ. Avatar answered Oct 10 '22 04:10

JJ.