Link to home
Start Free TrialLog in
Avatar of Joe Howard
Joe HowardFlag for United States of America

asked on

Regex Explanation

Can anybody please explain what this regex accepts. Please break it down.

("^[\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*@((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3}))$")
Looks to me email related, although I'm not convinced it's a correct email validation.

From left to right:
- Any word
- A dot followed by a word (any number of times)
- The @ sign

...and then it gets a bit funky... I think the top right part is essentially:

- Any word followed by a dot (any number of times)
- a 2-4 len word

...and the bottom right is an IP address

- 1-3 digits followed by a dot (3 times)
- 1-3 digits
Examples:
longwordwithnospaces@my-website-name.us
bob.jones@blah.com
jim@168.10.1.1
This editor allows you to enter test data and visualise the match.
https://www.debuggex.com

...it doesn't seem to understand the line start and line end in the regex though (the leading ^ and trailing $). Works well with those stripped i.e:
[\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*@((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3}))

Open in new window

SOLUTION
Avatar of ienaxxx
ienaxxx
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SAMIR BHOGAYTA
hi.. it is your answer

Expected one of *, +, ?, {, {,, (, [, ., \, $, |, ) at line 1, column 3 (byte 3) after ("
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@bigdogman, that's an excellent explanation.

It's worth adding that given that it looks like we're dealing with an email address, the domain of the address can be an ip address (ip4, not ip6) or just a standard domain name, though @ienaxxx already mentioned this.
Avatar of Joe Howard

ASKER

Wow! I wasn't expecting so many detailed explanations. Thank you all.
@Terry, interesting, I wasn't aware of that. Thanks for the explanation. :-)