let sampleWord = "astronaut";
let pwRegex = /^\D(?=\w{5,})(?=\w*\d{2,})/;
let result = pwRegex.test(sampleWord);
^
first character \D
should not be a number
(?=
in the tested string \w{5,})
should be 5 or more consecutive word characters
(?=
in the tested string \w*
should be zero or more consecutive word characters \d{2,})
followed by 2 or more consecutive numbers
word characters = alphanumeric (a-z 0-9) and underscore _
PS: https://regexr.com is a great tool for that. If you hover over some entered regex it explains each part to you.
1 Like
A tool you may get a lot of use out of:
Regex101 will give an explanation of all the parts of your regular expression. (It also allows you to write tests for your regex, etc).
2 Likes