Novice
Novice

Reputation: 1011

Mysql Regex Problem

I want to find only those rows whose column 'col' c doesn't contain characters from a-1. So I don't know how to write script. I've succeed to write script which is opposite to this. Thanks in Advance.

select * 
  from tbl_comment c 
 where c.`message` regexp '{a-z}';

I need the script which will be opposite to this. I've tried "not regexp" but it doesn't work.

Upvotes: 0

Views: 198

Answers (2)

Seth
Seth

Reputation: 46413

Try:

select * from tbl_comment c where c.message regexp '[^A-Z]'

or:

select * from tbl_comment c where c.message not regexp '[A-Z]'

Character class specifiers should be in square brackets.

(I'm assuming you meant "A-Z", not "A-1")

Upvotes: 1

Mark Byers
Mark Byers

Reputation: 837926

You need square brackets, not braces:

SELECT *
FROM tbl_comment c
WHERE c.`message` NOT REGEXP '[a-z]'

You also need to be careful what you mean. The above matches any row that doesn't contain any letters in a-z. If instead you want to match rows that contain at least one character not in a-z then you need this instead:

SELECT *
FROM tbl_comment c
WHERE c.`message` REGEXP '[^a-z]'

Upvotes: 2

Related Questions