^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))
@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)
+[a-zA-Z]{2,}))$
I could only understand parts of the regex but not the entire expression , like
([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)
match one or more characters that's are not the characters
<>()[\]\\.,;:\s@\" \\ Not sure what this [\]\\ and \s@\ means
I could understand some of the other parts as well but not as a single entity.
^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))
@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)
+[a-zA-Z]{2,}))$
I could only understand parts of the regex but not the entire expression , like
([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)
match one or more characters that's are not the characters
<>()[\]\\.,;:\s@\" \\ Not sure what this [\]\\ and \s@\ means
I could understand some of the other parts as well but not as a single entity.
Share Improve this question edited May 2, 2013 at 18:35 Stephanie Wilson 551 gold badge1 silver badge7 bronze badges asked May 2, 2013 at 18:13 Sushanth --Sushanth -- 55.8k9 gold badges69 silver badges107 bronze badges 12-
Where did you got that from? Is it a string passed to
new RegExp
, or did you omit literal delimiters? – Bergi Commented May 2, 2013 at 18:14 -
I was working with javascript validations , and came across it where it it was being used to test
email Address
I tried to understand it but in vain – Sushanth -- Commented May 2, 2013 at 18:16 - myezapp./apps/dev/regexp/show.ws Plug it in here for a visual explination of the capture groups ect. Here is yours: tinyurl./ccuqrwk – asawyer Commented May 2, 2013 at 18:16
-
The entries with a backslash in front of them are escaped characters that would have other meanings.
\]
is just the]
character, as that would normally end the class, and\\
is an escaped backslash, so just means the backslash itself.\s
is a special character class of whitespace. – Orbling Commented May 2, 2013 at 18:17 - 3 If you use a regex like this in your code, and I have to e along after you and figure it out, I WILL figure out where you live! “Always code as if the guy who ends up maintaining your code is a violent psychopath who knows where you live.” – DOK Commented May 2, 2013 at 18:21
3 Answers
Reset to default 5Here you go:
^(
(
[^<>()[\]\\.,;:\s@\"]+ // Disallow these characters any amount of times
(
\. // Allow dots
[^<>()[\]\\.,;:\s@\"]+ // Disallow these characters any amount of times
)* // This group must occur once or more
)
| // or
(\".+\") // Anything surrounded by quotes (Is this even legal?)
)
@ // At symbol is litterally that
(
// IP address
(
\[ // Allows square bracket
[0-9]{1,3} // 1 to three digits (for an IP address
\. // Allows dot
[0-9]{1,3} // 1 to three digits (for an IP address
\. // Allows dot
[0-9]{1,3} // 1 to three digits (for an IP address
\. // Allows dot
[0-9]{1,3} // 1 to three digits (for an IP address
\] // Square bracket
)
| // OR a domain name
(
([a-zA-Z\-0-9]+\.) // Valid domain characters are a-zA-Z0-9 plus dashes
+
[a-zA-Z]{2,} // The top level (anything after the dot) must be at least 2 chars long and only a-zA-Z
)
)$
Here is an easy to see illustration from debuggex.
"Not sure what this [\]\\
and \s@\"
means"
\]
is an escaped ]
\\
is an escaped \
\s
is any white space
@
is @
\"
is an escaped "
"what does the + mean"
+
means "one or more" of what precedes the +