Validating and Parsing Email Addresses Hacker Rank Solution – Queslers

Problem : Validating and Parsing Email Addresses Hacker Rank Solution

A valid email address meets the following criteria:

  • It’s composed of a username, domain name, and extension assembled in this format: [email protected]
  • The username starts with an English alphabetical character, and any subsequent characters consist of one or more of the following: alphanumeric characters, -,., and _.
  • The domain and extension contain only English alphabetical characters.
  • The extension is 1, 2, or 3 characters in length.

Given n pairs of names and email addresses as input, print each name and email address pair having a valid email address on a new line.
Hint : Try using Email.utils() to complete this challenge. For example, this code:

import email.utils
print email.utils.parseaddr('DOSHI <[email protected]>')
print email.utils.formataddr(('DOSHI', '[email protected]'))

produces this output:

('DOSHI', '[email protected]')
DOSHI <DOSHI@hackerrank.com>

Input Format :

The first line contains a single integer, n, denoting the number of email address.
Each line i of the n subsequent lines contains a name and an email address as two space-separated values following this format:

name <user@email.com>

Constraints :

  • 0 < N < 100

Output Format :

Print the space-separated name and email address pairs containing valid email addresses only. Each pair must be printed on a new line in the following format:

name <user@email.com>

You must print each valid email address in the same order as it was received as input.


Sample Input :

2  
DEXTER <dexter@hotmail.com>
VIRUS <virus!@variable.:p>

Sample Output :

DEXTER <dexter@hotmail.com>

Explanation :

[email protected] is a valid email address, so we print the name and email address pair received as input on a new line.
[email protected]:p is not a valid email address because the username contains an exclamation point (!) and the extension contains a colon (:). As this email is not valid, we print nothing.

Validating and Parsing Email Addresses Hacker Rank Solution in python 2

# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
N = input()
for i in xrange(N): 
    s = raw_input()
    a = re.search(r'<[a-zA-Z][\w\.-]*@[a-zA-Z]*\.[a-zA-Z]{1,3}>', s)
    if bool(a):
        print(s)

Validating and Parsing Email Addresses Hacker Rank Solution in python 3

# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
n = int(input())
for _ in range(n):
    x, y = input().split(' ')
    m = re.match(r'<[A-Za-z](\w|-|\.|_)[email protected][A-Za-z]+\.[A-Za-z]{1,3}>', y)
    if m:
        print(x,y)

Validating and Parsing Email Addresses Hacker Rank Solution in pypy

import email.utils
import re
n = int(raw_input())
for i in range(n):
    p = email.utils.parseaddr(raw_input())
    if re.match(r'[a-z][\w.-][email protected][a-z]+\.[a-z]{1,3}$', p[1], re.I):
        print email.utils.formataddr(p)

Validating and Parsing Email Addresses Hacker Rank Solution in pypy 3

# Enter your code here. Read input from STDIN. Print output to STDOUT

import re
import email.utils
n = int(input().strip())
temp =[]
a = re.compile(r'<[a-z0-9][\w._-][email protected][a-z]+\.[a-z]{1,3}>', re.I)
for _ in range(n):
    temp.append(input().strip())
for i, x in enumerate(temp):
    v =  a.search(x)
    if v:
        print(temp[i])
Validating and Parsing Email Addresses Hacker Rank Solution Review:

In our experience, we suggest you solve this VValidating and Parsing Email Addresses Hacker Rank Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

Validating and Parsing Email Addresses is available on Hacker Rank for Free, if you are stuck anywhere between compilation, just visit Queslers to get all Hacker Rank Solution

Validating and Parsing Email Addresses Hacker Rank Solution Conclusion:

I hope this Validating and Parsing Email Addresses Hacker Rank Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Hacker Rank Problem & Solutions >>

Mini-Max Sum Hacker Rank Solution

String Validators Hacker Rank Solution

Text Alignment Hacker Rank solution

String validators Hacker Rank Solution

Staircase Hacker Rank Solution

Leave a Reply

Your email address will not be published.