mysql – SQL REGEXP Wrong string matched

When including dash (-) in a regular expression, put it first, else it will be treated as a character range (as you do with A-Z.

So change to

where mail regexp '^[a-zA-Z][-a-zA-Z0-9._]*@leetcode.com$'

The . in leetcode.com will match any character. Technically, you should do either [.] or perhaps \. or \\., depending on the version of regexp.)

leetcode?com matches either leetcodecom or leetcodcom — probably not what you wanted. ? says that the previous thing (e) is optional.

You may want + instead of * — email addresses probably require “at least one character”, not “zero or more characters”.

Read more here: Source link