Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Exp14-Python

The document outlines an experiment to validate usernames, passwords, and URLs using regular expressions (regex). It explains various metacharacters and special characters used in regex, provides rules for validating 10-digit mobile numbers, and includes a Python program for password validation. The conclusion states that the implementation of regex expressions has been successfully demonstrated.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Exp14-Python

The document outlines an experiment to validate usernames, passwords, and URLs using regular expressions (regex). It explains various metacharacters and special characters used in regex, provides rules for validating 10-digit mobile numbers, and includes a Python program for password validation. The conclusion states that the implementation of regex expressions has been successfully demonstrated.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

EXPERIMENT NO: 14

AIM: To validate username, password and url using regular expressions


THEORY: Regular expressions, often shortened as regex are a sequence of characters used to
check whether a pattern exists in a given text/string or not.
METACHARACTERS:
[ ] - The set of characters - “[a-e]”
 - Any character – “he.ϴ”
˄ - Starts with – “^python”
\ - Signals a special sequence
* - Zero or more occurrences - “aix*”
+ - One or more occurrences - “aix+”
{ } - Exactly the specified number of occurrences – “al{2}”
| - Either or – “code|char”

SPECIAL CHARACTERS
\A – Returns a match if the specified characters are at the beginning of the string
\b – Returns a match where the specified characters are at the beginning or at the end of a word
\B – Returns a match where the specified characters are present, but NOT at the beginning or at
end of a word.
PROGRAMS:
Write a Regular Expression to represent all 10 digit mobile numbers
Rules:
1. Every number should contain exactly 10 digits
2. The first digit should be 7 or 8 or 9
password validation:
import re

def validate_password(password):
# define our regex pattern for validation
pattern = r"^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$"

# We use the re.match function to test the password against the pattern
match = re.match(pattern, password)

# return True if the password matches the pattern, False otherwise


return bool(match)

password1 = "StrongP@ssword123"
password2 = "weakpassword"
print(validate_password(password1))
print(validate_password(password2))

CONCLUSION: Thereby, we have implemented regex expression.

You might also like