Learn with Yasir

Share Your Feedback

Regular Expressions in Python: Coding Exercises


Regular Expressions in Python: Coding Exercises

Exercise #1

Write a Python program that asks the user to enter a password and checks whether it is valid based on the following rules:

  1. The password must be at least 8 characters long.
  2. It must contain at least one uppercase letter (Aโ€“Z).
  3. It must contain at least one lowercase letter (aโ€“z).
  4. It must contain at least one number (0โ€“9).
  5. It must contain at least one special character (e.g., !@#$%^&*()_+-=[]{}|;:'",.<>?/).

Click here to see the solution โœจ

Exercise #2

Write a function that extracts all phone numbers from a given string. Assume phone numbers follow the format XXX-XXX-XXXX.

Exercise #3

Create a program that validates a given username. The username must start with a letter and contain only letters, digits, and underscores.


๐Ÿง  Practice & Progress