Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 902
toki Avatar asked Mar 30 '14 01:03

toki


People also ask

What does this regular expression mean [\ s ]+$?

The Difference Between \s and \s+ The plus sign + is a greedy quantifier, which means one or more times. For example, expression X+ matches one or more X characters. Therefore, the regular expression \s matches a single whitespace character, while \s+ will match one or more whitespace characters.

What does \+ mean in regex?

Example: The regex "aa\n" tries to match two consecutive "a"s at the end of a line, inclusive the newline character itself. Example: "a\+" matches "a+" and not a series of one or "a"s. ^ the caret is the anchor for the start of the string, or the negation symbol. Example: "^a" matches "a" at the start of the string.

What does \d mean in regex?

The RegExp \D Metacharacter in JavaScript is used to search non digit characters i.e all the characters except digits. It is same as [^0-9]. Syntax: /\D/


1 Answers

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
like image 104
abc123 Avatar answered Sep 18 '22 12:09

abc123