简体   繁体   中英

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.xxxxxXXXXX@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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM