Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#project 7

import re

text = "The new registrations are potter709@gmail.com , elixir101@gmail.com. If you


find any disruptions, kindly contact granger111@gamil.com or severus77@gamil.com "

# Define a regular expression to match email addresses

email_regex = r'\b\w+@\w+\.\w{2,}\b'

#r at the beginning of the pattern is used to indicate that this is a raw string in
Python,
#\b matches a word boundary, which is the point where a word character (i.e., a
letter, digit, or underscore) is adjacent to a non-word character
#(i.e., a space, punctuation mark, or the beginning or end of a line).
#\w+ matches one or more word characters, which can include letters, digits, and
underscores.
#@ matches the "@" symbol that separates the username and domain name in an email
address.
#\., which is a backslash followed by a period, matches a literal period character.
#\w{2,} matches two or more word characters in the top-level domain name (e.g.,
com, org, edu).
#\b matches another word boundary, which ensures that the pattern only matches
complete email addresses
#and not partial matches.

# Use the findall() method to extract all email addresses in the text

email_addresses = re.findall(email_regex, text)

# Extract usernames from email addresses using string slicing

email_addresses = re.findall(email_regex, text)


#[0] for potter709,elixir101,granger111,severus77
#[1] for gamil
#[2] for out of range

usernames = [email.split('@')[0] for email in email_addresses]

print(usernames)

You might also like