Home computickets Regular expression for email

Regular expression for email

Author

Date

Category

There is a regular expression for checking email:

pattern = "^ [a-za-z0-9] [a-za-z0-9 \ .- _] * [A-ZA-Z0-9] * @ ([A-ZA-Z0-9] + ([A-ZA-Z0-9 -] * [A-ZA-Z0-9] +) * \ .) + [A-ZA-Z] * $ "

Tell me, please, why not miss:

[email protected]

At the same time [email protected] and [email protected] skips.


Answer 1, Authority 100%

Because hyphen also needs to be shielded using reverse slash:

pattern = "^ [a-za-z0-9] [a-za-z0-9 \. \ -_]

Since in the current entry \.-_ The hyphen sign is perceived as a range of a range, and not as one simple symbol.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions