Joe Howard
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}))$")
("^[\w!#$%&'*+\-/=?\^_`{|}
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
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-we bsite-name .us
bob.jones@blah.com
jim@168.10.1.1
longwordwithnospaces@my-we
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:
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}))
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hi.. it is your answer
Expected one of *, +, ?, {, {,, (, [, ., \, $, |, ) at line 1, column 3 (byte 3) after ("
Expected one of *, +, ?, {, {,, (, [, ., \, $, |, ) at line 1, column 3 (byte 3) after ("
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@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.
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.
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. :-)
http://www.regexper.com/#%5E%5B%5Cw!%23%24%25%26'*%2B%5C-%2F%3D%3F%5C%5E_%60%7B%7C%7D~%5D%2B(%5C.%5B%5Cw!%23%24%25%26'*%2B%5C-%2F%3D%3F%5C%5E_%60%7B%7C%7D~%5D%2B)*%40(((%5B%5C-%5Cw%5D%2B%5C.)%2B%5Ba-zA-Z%5D%7B2%2C4%7D)%7C((%5B0-9%5D%7B1%2C3%7D%5C.)%7B3%7D%5B0-9%5D%7B1%2C3%7D))%24