-4

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

baao
  • 62,535
  • 14
  • 113
  • 168
  • looks like this is validating an email-adress – CoderPi Nov 24 '15 at 17:54
  • is this your homework ? – CoderPi Nov 24 '15 at 17:55
  • Read the description on the right - https://regex101.com/r/wO6aN1/1 – OneCricketeer Nov 24 '15 at 17:58
  • 2
    What that regex means is that its author doesn't know anything about regexes. `\w` already matches digits, `{1,}` is the same as `+`, the second `.` should be `\.`, and `[A-z]` is **not** how you match letters case-insensitively. And if the regex is meant to validate email addresses, the author doesn't know anything about those, either. – Alan Moore Nov 24 '15 at 18:44

3 Answers3

1

Looks like a crude regex to check for an email address. Not the proper complete one, mind you (it's a lot longer).

Kayaman
  • 67,952
  • 3
  • 69
  • 110
0
  • ^ 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


So my guess is that this was a poor's man attempt at email validation. Here is the simplified version with the [A-z] shenanigan fixed:
/^[\w.-]+@[A-Za-z0-9]+\.[A-Za-z]{3}$/

See it in action


As for something which satisfies the original regex - .@A.AAA
ndnenkov
  • 33,260
  • 9
  • 67
  • 97
0

You should checkout http://regexper.com which illustrates regular expressions (Note, I fixed the escaping of the period for you):

Regex

From the illustration you can see it is checking for:

  1. The start of the string
  2. One or more characters of: a word character, period or dash
  3. Followed by a single "@" symbol
  4. Followed by one or more characters within the ranges of A-z or 0-9
  5. Followed by a period
  6. Followed by three characters within the range of A-z
  7. The end of the string

as @Kayaman mentions, it's a crude regular expression for an email address, though is an encompassing expression to find any valid email.

rgthree
  • 6,849
  • 15
  • 20