Exercise - pos and neg lookahead

Thanks for the time taken to respond to what is probably quite a simple few questions.

let sampleWord = "astronaut";
let pwRegex =  /(?=\w{6})(?=\w*\d{2})/;
let result = pwRegex.test(sampleWord);
  1. what does \w* mean, 0 or more occurrences of \w? The previous example had \D* which I found quite confusing.

  2. What part of the code ensures that the 2 digits are consecutive and not separated by letters?

Thanks again.

a star means zero or more occurrence. \D means Not a \d. You might want to use a parentheses for grouping. You better google for regex cheatsheet. Also you can learn more in MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.