Reputation: 3542
I am trying to return customers in our database that have special characters in their email address (other than + . - @ _
). Here is my current query:
SELECT UserID, FirstName, LastName, Email
FROM Customer
WHERE Email REGEXP '[^A-Za-z0-9\\@\\.\\-\\+\\_]' and Active = 1 and Enabled = 1;
But the data set returned still contains emails like [email protected]
. Shouldn't this REGEXP be ignoring email addresses like this?
Upvotes: 0
Views: 631
Reputation: 89557
I think that the problem comes from the hyphen that is used in a character class to define a range, so it isn't seen as a literal character. Try to write this:
Email REGEXP '[^A-Za-z0-9@.+_-]'
If you put it at the end (or at the start) it is no more ambigous.
Upvotes: 5