Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a regular expression to verify email input based on pattern. 1

Status
Not open for further replies.

stla

IS-IT--Management
Mar 12, 2003
190
DE
(Elementary user)

I am involved in a project where a regular expression must check the email input of a user.

The user can be 'anyone' as long as the characters after '@' match either 'abcd.br or 'abcd-rio.br'.

For example: jon@abcd.br or jane@abcd-rio.br

Can anyone help me with my below synatx:

.*@abcd.br|.*@abcd-rio.br

Best regards
 

What help do you need? Depending upon your application, your initial syntax looks okay:

Code:
# echo "friends@abcd.br" | egrep  '.*@abcd.br|.*@abcd-rio.br'
friends@abcd.br
 
It worked!
Thanks, I thought I needed brackets.
 
stla,

Actually, to pull the e-mail address out of some text, you would need to use brackets as in '[a-zA-Z0-9_]+' or the '\w+'. Also, you should preserve the literal '.' in your strings, otherwise as a regular expression they will match any character when you really want to match a dot as in ".br".

Here is an example that pulls out the e-mail addesses that match your specifications:

Code:
echo "friends@abcd.br are fun, but river folks \
are at riofolks@abcd-rio.br \
and at riofolks@gmail.com " | \
grep -Eo -e '\w+@abcd\.br|\w+@abcd-rio\.br'

Notice that only text that matched the regular expression is printed:
Code:
friends@abcd.br
riofolks@abcd-rio.br

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top