Quick explanation
/
JavaScript regular expressions start with a /
and end with another one. Everything in-between is a regular expression. After the second /
there may be switches like g
(global) and/or i
(ignore case) ie. var rx = /.+/gi;
)
^
Start of a text line (so nothing can be prepended before the email address). This also comes in handy in multi-line texts.
\
Used to escape special characters. A dot/full-stop .
is a special character and represents any single character but when presented as \.
it means a dot/full-stop itself. Characters that need to escaped are usually used in regular expression syntax. (braces, curly braces, square brackets etc.) You'll know when you learn the syntax.
\.\-
Two escaped characters. Dot/full-stop and a minus/hyphen. So it means .-
$
End of line.
Learn regular expressions
They are one of the imperative things every developer should understand to some extent. At least some basic knowledge is mandatory.
Some resources