Skip to content

Instantly share code, notes, and snippets.

@nickihastings
Created October 10, 2019 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickihastings/2afd147f407b8dd9b77e6d2bc7bbea9f to your computer and use it in GitHub Desktop.
Save nickihastings/2afd147f407b8dd9b77e6d2bc7bbea9f to your computer and use it in GitHub Desktop.
Use lookaheads in the pwRegex to match passwords that are greater than 5 characters long and have two consecutive digits.
let sampleWord = "astronaut";
let pwRegex = /(?=\w{5,})(?=\w+\d{2})/; // Change this line
let result = pwRegex.test(sampleWord);
// Your regex should use two positive lookaheads.
// Your regex should not match "astronaut"
// Your regex should not match "airplanes"
// Your regex should not match "banan1"
// Your regex should match "bana12"
// Your regex should match "abc123"
// Your regex should not match "123"
// Your regex should not match "1234"
@muhammadbilal20130
Copy link

/(?=\w{5,})(?=\D\w*\d{2})/
this'll work

@Mainaaa1
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment