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