Do you understand the regular expression in this way?

Source: Internet
Author: User
Do you understand regular expressions in this way? the regular expressions written by others are as follows:
If (! Preg_match ('/^ [\ w \-\.] + @ [\ w \-\.] + (\. \ w +) + $/', $ _ string ))
I understand the brackets and their meanings as follows: Brackets indicate any of them;
Then, [\ w \-\.] in the above section can be understood as the first one that can be followed by any English character, horizontal bar, or dot.

If the above understanding is correct, the problem arises. the purpose of this code is to verify the correctness of the email.
We all know that the first hit in an email cannot be a horizontal bar. isn't that wrong?


Reply to discussion (solution)

Nowadays, many email verification methods are rough, because some service providers do support odd writing. I think it is better to miss the network and avoid mistakes.
Attaches a dropbox foreign website with the source code verified by email:

$r = preg_match('/^[A-Za-z0-9!#$%&\'*+\/=?^_`{|}~-]+(\.[A-Za-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*\.([A-Za-z]{2,})$/', $email);

Nowadays, many email verification methods are rough, because some service providers do support odd writing. I think it is better to miss the network and avoid mistakes.
Attaches a dropbox foreign website with the source code verified by email:

$r = preg_match('/^[A-Za-z0-9!#$%&\'*+\/=?^_`{|}~-]+(\.[A-Za-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*\.([A-Za-z]{2,})$/', $email);


You are two! I am asking about my understanding, right?

Your regular expression can match... @ ....Net
Are you right?


Nowadays, many email verification methods are rough, because some service providers do support odd writing. I think it is better to miss the network and avoid mistakes.
Attaches a dropbox foreign website with the source code verified by email:

$r = preg_match('/^[A-Za-z0-9!#$%&\'*+\/=?^_`{|}~-]+(\.[A-Za-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*\.([A-Za-z]{2,})$/', $email);


You are two! I am asking about my understanding, right?



Your attitude is doomed to your development.

\ W uppercase/lowercase English letters, numbers, and underscores
This regular expression matches. @... _ @ _. _-@--. 0 .....
Regular expression problems

Understanding is okay, and attitude is wrong.

Fuck you, there's a problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.