Reputation: 3225
I have the following query:
SELECT COUNT(*)
FROM 'users'
WHERE (
summary REGEXP '^\\(?[\\d]{3}\\)?[\\s-]?[\\d]{3}[\\s-]?[\\d]{4}$' OR
bio REGEXP '^\\(?[\\d]{3}\\)?[\\s-]?[\\d]{3}[\\s-]?[\\d]{4}$' OR
about_me REGEXP '^\\(?[\\d]{3}\\)?[\\s-]?[\\d]{3}[\\s-]?[\\d]{4}$'
);604-456-1234
I already tested the regex here --> http://rubular.com/ and it works for my cases.
I have one user with the following string on its bio "604-456-1234" and it should be returned but is not.
Why?
Upvotes: 3
Views: 867
Reputation: 5608
My mistake you are doing it wrong [\d] doesn't work, you need to use [0-9], so using:
'^\\(?[0-9]{3}\\)?[\\s-]?[0-9]{3}[\\s-]?[0-9]{4}$'
Works, specifically look here: http://dev.mysql.com/doc/refman/5.1/en/regexp.html there is no reference to \d
being supported
Upvotes: 3