Regular Expression — Email Checker
What is Regular Expression?
Regular Expression (RE) is a notation that can describe the pattern of the word.
On this occasion, I will show you one example of a Regular Expression application using python on an email checker program. Before that, I used the data provided by DQLab.
To start this programming, I would always import the library first.
#import the library
import reNext is, I will create a function named email_check. This function will filter some emails using Regular Expression in python programming languages. This function will receive a parameter called input. The input parameter contains an email, and an output will be a Pass or Not Pass.
#function email_check
def email_check(input):
match = re.search('(?=^((?!-).)*$)(?=[^0-9])((?=^((?!\.\d).)*$)|(?=.*_))',input)
if match:
print('Pass')
else:
print('Not Pass')In email_check, I used the function of the library re, which is search(). This search() function returns a match object if there is a match anywhere in the string. After creating an email_check function, I will insert the existing email data at Table 1 into a list.
#Create a list of email
emails = ['my-name@someemail.com',
'myname@someemail.com',
'my.name@someemail.com',
'my.name2019@someemail.com',
'my.name.2019@someemail.com',
'somename.201903@someemail.com',
'my_name.201903@someemail.com',
'201903myname@someemail.com',
'201903.myname@someemail.com']The last step I am going to do is checking. I am using FOR Looping with a variable named email to iterate a variable called emails. The output from FOR Looping is a Pass or Not Pass.
When I run the program, it will produce an output like Figure 1.
That’s it from me; you can reach out to me if you have a critique, advice, or question about this Regular Expression Project. Thank you, I really appreciate you taking the time to read this.
Get Luthfi Fathurrahman’s stories in your inbox
Join Medium for free to get updates from this writer.
Code: https://gist.github.com/luthfif22/582760075660da2aab47780fa89a48c2
LinkedIn: https://www.linkedin.com/in/luthfi-fathurrahman/






