Claude Sonnet 5.5
Breaking down ^(?=.*[A-Z])(?=.*\d)[A-Za-z\d]{8,}$
Piece by piece
| Part | Meaning |
|---|---|
^ | Anchors the match to the start of the string. |
(?=.*[A-Z]) | Positive lookahead: from the current position (the start), there must be somewhere ahead (.* = any characters, including none) an uppercase letter [A-Z]. It checks without consuming characters. |
(?=.*\d) | A second lookahead, also starting at the beginning: somewhere in the string there must be a digit (\d). |
[A-Za-z\d] | The characters actually allowed: uppercase letters, lowercase letters, or digits. |
{8,} | The preceding character class must repeat 8 or more times, with no upper limit. |
$ | Anchors to the end of the string, so the whole string must be made of allowed characters. |
How it works together
Both lookaheads run from position 0 and don't move the cursor, so they act as independent "must contain" checks. Then [A-Za-z\d]{8,} consumes the whole string and enforces the length and character set.
In effect, this is a simple password rule: at least 8 characters, only letters and digits, with at least one uppercase letter and at least one digit. (Lowercase letters are allowed but not required.)
Strings it matches
Password1: 9 characters, has uppercasePand digit1, all alphanumeric.12345678A: 9 characters, has digit(s) and uppercaseA. (Order doesn't matter.)
Strings it rejects
password1: has a digit but no uppercase letter, so the first lookahead fails.Pass word1(orPassw0rd!): contains a space (or!), which isn't in[A-Za-z\d], so the character class fails to reach$.
Other rejections: Pass1 (too short, only 5 characters) and PasswordOnly (no digit).