Question

In: Computer Science

PYTHON Write a regular expression that will accept any properly formatted email address, and reject any...

PYTHON

Write a regular expression that will accept any properly formatted email address, and reject any invalid email address. An example of a valid inputted email address would be "[email protected]".

Solutions

Expert Solution

# Python program to validate an Email 
# re module provides support 
# for regular expressions 

import re 
  
# Make a regular expression 
# for validating an Email 
regex = '^[a-zA-Z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$'
# for custom mails use: '^[a-zA-Z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w+$' 
      
# Define a function for 
# for validating an Email 
def check(email):  
  
    # pass the regular expression 
    # and the string in search() method 
    if(re.search(regex,email)):  
        print("Valid Email")  
          
    else:  
        print("Invalid Email")  
      
  
# Driver Code  
if __name__ == '__main__' :  
      
    # Enter the email  
    email = input("Enter your email : ")
    check(email)

Output :


Related Solutions

Python Write a program that will analyse the string input and print “accept” or “reject” based...
Python Write a program that will analyse the string input and print “accept” or “reject” based on the pattern given Accept if it fulfils the following conditions -String length 9 -3 small alphabet (3 lowercase letter) -3 digits -3 big alphabet (3 uppercase letters) -1st alphabet should be a capital -Last alphabet should be a number -Two consecutive alphabets can't be small Reject if any of the conditions is absent So i want it to accept or reject my input,...
Create and test a python regular expression that matches a street address consisting of a number...
Create and test a python regular expression that matches a street address consisting of a number with one or more digits followed by two words of one or more characters each. The tokens should be separated by one space each, as in 123 Main Street.
Write a regular expression, using the regular expression syntax used by lex, that matches any finite...
Write a regular expression, using the regular expression syntax used by lex, that matches any finite decimal representation of a nonnegative real number.
: Create a Java program that will accept a regular expression and a filename for a...
: Create a Java program that will accept a regular expression and a filename for a text file. The program will process the file, looking at every line to find matches for the regular expression and display them. Regular Expression Format : The following operators need to be accepted: + - one or more of the following character (no groups) * - zero or more of the following character (no groups) [] – no negation, no character spans – the...
I am confused with Python I have to write a specification for an email address. In...
I am confused with Python I have to write a specification for an email address. In one string a valid email address and the other without a valid email address. Ex: print(text_match("My teacher’s email is [email protected]")) print(text_match("My teacher has no email address"))
Q1 Write a python regular expression to match a certain pattern of phone number.             ###...
Q1 Write a python regular expression to match a certain pattern of phone number.             ### Suppose we want to recognize phone numbers with or without hyphens. The ### regular expression you give should work for any number of groups of any (non- ### empty) size, separated by 1 hyphen. Each group is [0-9]+. ### Hint: Accept "5" but not "-6" ### FSM for TELEPHONE NUMBER IS: # state:1 --[0-9]--> state:2 # state:2 --[0-9]--> state:4 # state:2 --[\-]---> state:3 #...
1. What is a regular expression? Write a regular expression that will detect “College” and “collegE”....
1. What is a regular expression? Write a regular expression that will detect “College” and “collegE”. 2. What is degree centrality? Create a graph of 4 vertices and compute the degree centrality of the vertices. 3. Compute internal and external community densities for a graph containing 6 nodes. You can create any graph of 6 nodes with at least 4 edges.
Write a regular expression that can represent any digit, without more than one digit or non...
Write a regular expression that can represent any digit, without more than one digit or non digit characters.
How do you write a letter to directors advising them whether to accept or reject an...
How do you write a letter to directors advising them whether to accept or reject an investment?
The coding must be formatted in Python. Write a function matrix_power(A, n) that computes the power...
The coding must be formatted in Python. Write a function matrix_power(A, n) that computes the power An using Boolean arithmetic and returns the result. You may assume that A is a 2D list containing only 0s and 1s, A is square (same number of rows and columns), and n is an integer ≥ 1. You should call your previously written matrix multiply boolean function. Example: Let R = [ [0, 0, 0, 1], [0, 1, 1, 0], [0, 0, 0,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT