Exercise: Extract Email Addresses

Use regular expressions to extract email addresses from a file.

Problem statement

In this challenge, you have to extract and print all email addresses from a given file.

For simplicity, you may assume that:

  • An email address follows the pattern <username>@<domain>.<top level domain>, where each component <..> consists of alphanumeric characters and underscores. So, for example, for the email address Commonman@dc.com.pk, Commonman will be the username, dc will be the domain, com will be the top-level domain, and pk will be the country code top-level domain (ccTLD).

  • It may be followed by a two- or three-letter long <country code> consisting of letters of the English alphabet.

Sample input

Get hands-on with 1200+ tech skills courses.