Can someone elaborate the following regular expression:
/^[\w0-9.-]{1,}@[A-z0-9]{1,}.[A-z]{3}$/
and also give some sample strings that satisfy this regular expression? Thanks
Can someone elaborate the following regular expression:
/^[\w0-9.-]{1,}@[A-z0-9]{1,}.[A-z]{3}$/
and also give some sample strings that satisfy this regular expression? Thanks
Looks like a crude regex to check for an email address. Not the proper complete one, mind you (it's a lot longer).
^
beginning of string[\w0-9.-]
- word character, a digit, a dot or a dash. Doesn't make that much sense as word characters include digits too, so it can be simplified to [\w.-]
{1,}
- one or more of those. There is an equivalent +
, it's better to use that instead@
- at sign[A-z0-9]
- a terrible idea to mix capital and lower case letters. As it is right now, this means all ascii characters from A
to z
plus digits.
- any character. I'm guessing it should have been a literal dot - \.
[A-z]{3}
- three characters, again as above$
- end of line[A-z]
shenanigan fixed:
/^[\w.-]+@[A-Za-z0-9]+\.[A-Za-z]{3}$/
.@A.AAA
You should checkout http://regexper.com which illustrates regular expressions (Note, I fixed the escaping of the period for you):
From the illustration you can see it is checking for:
as @Kayaman mentions, it's a crude regular expression for an email address, though is an encompassing expression to find any valid email.