mySQL string matching
I am needing to query my database to find records that fall between 2 dates (this is simple enough) however I need to refine the search so that it only finds records where the email falls within certain constraints, basically I need to delete any row that falls between 2 dates and has a format of
x.xxxxxXXXX开发者_StackOverflow中文版X@xxxxxxxx.xxx
basically I need to look for email address that start with a letter followed by full stop and have 5 numbers before the @ sign. Is this possible with mySQL and if so how, and if not how could I search for these email address with PHP?
You need to use regular expressions. MySQL 5.1 supports these: documentation page. This also can be done in PHP using preg_match.
You regurlar expression could look like: [a-zA-Z]\.[a-zA-Z]+[0-9]{5}@.+
You could also use like, if you find it useful. Example
LIKE '_.__________@______.___'
However, it will not detect numbers. In that case you have to use regex
docs
Regex should be like this: (changed from example above)
[a-zA-Z]{1}\.[a-zA-Z]+[0-9]{5}@([_a-z0-9\-])\.[a-zA-Z]
精彩评论