This article describes an issue that is encountered when using regular expressions in PHP to match a mailbox (email), and a workaround. Please refer to the friends who are in need. The PHP regular expression matches the mailbox with the following code: Why is the output above legitimate? {2,10} Here is not only 2 to 10 digits, but the above mailbox is more than 10 bits. This regular match is matched to the 1412424545645454 mismatch in the front part of this section ' 545454545k@qq.com ', so it's still legal. Matches correctly and can be modified to: $a = '/^ ([\w\.\_]{2,10}) @ (\w{1,}). ([a-z]{2,4}) $/'; Note the regular:/([\w\.\_]{2,10}) @ (\w{1,}). ([a-z]{2,4})/It has no assertion, meaning that as long as there is a match in the string, the {2,10} is only 2 to 10 bit matched, but not for the entire string as long as there is a partial match. An assertion is used to determine whether a whole string is matched. such as ^ $/^ ([\w\.\_]{2,10}) @ (\w{1,}). ([a-z]{2,4}) $/Note that the header and tail add ^ $ Perfect code, as follows: |