Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

HackerRank Validating and Parsing Email Addresses solution in python

YASH PAL, 31 July 2024

In this Validating and Parsing Email Addresses problem, you have 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.

HackerRank Validating and Parsing Email Addresses solution in python

Problem solution in Python 2 programming.

# 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)

Problem solution in Python 3 programming.

# 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|-|.|_)+@[A-Za-z]+.[A-Za-z]{1,3}>', y)
    if m:
        print(x,y)

Problem solution in pypy programming.

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.-]+@[a-z]+.[a-z]{1,3}$', p[1], re.I):
        print email.utils.formataddr(p)

Problem solution in pypy3 programming.

# 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._-]+@[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])

coding problems solutions Python Solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes