What is the meaning of [\w\-] regular expression in PHP

preg-match, regex

Solution

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

Problem

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.

Original source