Reputation: 48933
I know this is a pretty basic regex, could someone explain what it is doing please?
^[^@]+@[-a-z0-9.]+$
Upvotes: 0
Views: 185
Reputation: 43159
I think it's trying to match an email address (not very well)
Example matches:
[email protected]
[email protected]
hello(world)@9
a[]&^&£^$^&£@.
Upvotes: 5
Reputation: 50215
To expand upon Rex's answer, it looks like a naive email validation regex.
Upvotes: 0
Reputation: 89055
^ - 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.
Upvotes: 9
Reputation: 63435
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.
Upvotes: 1
Reputation: 144112
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").
Upvotes: 2