tags:

views:

84

answers:

5

I know this is a pretty basic regex, could someone explain what it is doing please?

^[^@]+@[-a-z0-9.]+$
+2  A: 

It says "match one or more non-@ character followed by an @, followed by one or more alphanumeric characters, a - or a ." The ^ at the beginning and the $ at the end signify this pattern must also be against the beginning and end of the entire string (^ means "beginning of string" and $ means "end of string").

Rex M
You missed the + after [^@]
moonshadow
The [^@]+ matches one OR MORE non-@ characters.
TLiebe
@moon @tliebe Oops, thanks
Rex M
+1  A: 

Matches a string that doesn't start with at least 1 @ character, followed by matching a @, then a -, . or any alphanumeric characters at least once.

I'm guessing it's a very loose email validator.

John Rasch
+8  A: 

^ - match start of string

[^@]+ - match one or more characters that aren't an @

@ - match an @

[-a-z0-9.]+ - match one or more characters from the set '-', lower case 'a'-'z', the digits '0'-'9', '.'

$ - match end of string

So, match any string that consists of some characters that aren't '@', followed by '@', followed by some number of lower case letters / digits / dashes / full stops.

moonshadow
A: 

To expand upon Rex's answer, it looks like a naive email validation regex.

Austin Salonen
+4  A: 

I think it's trying to match an email address (not very well)

Example matches:

Simon Nickerson