Password Rules via Lookaheads

Hard ⏱ 18 min 28% acceptance ★★★★★ 4.6
Write strong(pw) validating in a single regex with lookaheads: at least 8 chars, one lowercase, one uppercase, one digit. Each (?=...) asserts without consuming — the idiomatic multi-rule validator.

Examples

Example 1
Input
strong('Passw0rd')
Output
True
Explanation

All four rules hold.

Example 2
Input
strong('password')
Output
False
Explanation

No uppercase, no digit.

Constraints

  • One fullmatch pattern with three lookaheads.
  • No separate any() checks.

Topics

Regular Expressionslookaheads

Companies

OktaAuth0Microsoft

Hints

Hint 1

r'(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}'.

Hint 2

Lookaheads all anchor at position 0.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.