Hi All,
Regular expression is used to validate input. Python have a library which have many methods to use regular expression.
Regular Expression :- A regular expression (or RE) specifies a set of strings that matches it.
The functions in re library of python, let you check if a particular string matches a given regular expression (or if a given regular expression matches a particular string).
Email Validation using RE :-
def emailValidation():
email = input("enter the mail address::")
match = re.search(r'[\w.-]+@[\w.-]+.\w+', email)
if match :
print("success")
else:
print("failed")
Before above code just import re
, you can validate any string just pass regular expression and object that contain value to search method , it will return you boolean value ,true if matches otherwise false.
0 Comment(s)