Domanda

I was trying to understand about validating email in the following link - http://www.w3schools.com/PHP/php_form_url_email.asp

I know that \w means alphanumeric characters i.e. [0-9a-zA-Z] and - should mean to include a "-" as well. I got confused because they have used it after the "." as well, I think that after "." only alphanumeric characters can appear such as "com" , "org" etc.

È stato utile?

Soluzione

Regex 101

\w explained

\w match any word character [a-zA-Z0-9_]

\w\- explained

\w\-
    \w match any word character [a-zA-Z0-9_]
    \- matches the character - literally

Matching Email Addresses Simple, not future proof

\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\b

Altri suggerimenti

\w means [a-zA-Z0-9_]

and

\- means - (literal) in a character class.

Thus [\w\-] means [a-zA-Z0-9-]

note that escaping - in a character class is useless if it is at the first or last position.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top