easy +8 pts

Lookahead Validation

Validate passwords with regex lookaheads for uppercase, digit, and special character.

Implement a function `validate_password(password: str) -> bool` that returns `True` if the password meets all of the following requirements, and `False` otherwise. Requirements: 1. Length is at least 8 characters. 2. Contains at least one uppercase letter (A-Z). 3. Contains at least one digit (0-9). 4. Contains at least one special character from the set `!@#$%^&*`. The password may contain any other characters (including lowercase letters and spaces). Use regular expressions (lookaheads) to check these conditions. Do **not** manually loop through the string. Write your solution in the `validate_password` function.

Constraints

- `password` is a string with length between 0 and 1000. - Only standard ASCII characters are used. - Your solution must use regular expressions; manual character-by-character checks are not allowed. - The time complexity should be O(n) where n is the password length (regex compilation allowed once).

Example

>>> validate_password('Passw0rd!')
True
>>> validate_password('password1!')
False   # no uppercase
>>> validate_password('PASSWORD1')
False   # no special
>>> validate_password('Passw0rd')
False   # too short (7 chars), no special
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use a single regex with positive lookaheads: `(?=.*[A-Z])`, `(?=.*[0-9])`, `(?=.*[!@#$%^&*])`.
Anchor the pattern with `^` and `$` and set the length with `.{8,}`.
You can compile the pattern once outside the function for efficiency.
Remember to use `re.fullmatch` or `^...$` to ensure the entire string is considered.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.