Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a regular expression in unix/linux that validates an email address. The r

ID: 3775155 • Letter: C

Question

Create a regular expression in unix/linux that validates an email address. The rules of a valid email address are:

- An email address consists of: username@domain

- Domain consists of label and domain name . Domain can not start with a dot. Multiple label can be separated with periods. No two periods in succession can be in a domain name A label may contain hyphens, but no two hyphens in a row. A label must not start nor end with a hyphen.

- Username can not contain any space

- Top level domain names: e.g, com, org, edu, gov, net, tv. Wikipedia maintains a comprehensive list of top-level domain names at http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains.

Explanation / Answer

Regular expression in unix/linux that validates an email address:

regex='^(([^<>()[]\.,;:s@"]+(.[^<>()[]\.,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$'

i="test@terra.es"

if [[ $i=~$regex ]] ; then
echo "OK"
else
echo "not OK"
fi

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote