Positive and Negative Lookahead - Apex

Tell us what’s happening:
I am receiving the following error:
// running tests Your regex should match

“bana12”
Your regex should match
“abc123”
Your regex should match
“astr1on11aut”
// tests completed

Your code so far

        let sampleWord = "astronaut";
let pwRegex = /^\D(?=\w{5,})(?=\d\d)/; // Change this line
let result = pwRegex.test(sampleWord);```js

let sampleWord = "astronaut";
let pwRegex = /^\D(?=\w{5,})(?=\d\d)/; // Change this line
let result = pwRegex.test(sampleWord);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15.

Challenge: Positive and Negative Lookahead

Link to the challenge:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Need more info. What do you think is wrong? What have you tried? What’s happening instead?

this is an issue I see often: lookaheads look forward, but they actually match a 0-dimentional part of the string
it means that both lookahead will check starting from same character, essentially you are saying that second and third characters of the string must be numbers

It should match the following but it is not

// running tests Your regex should match

"bana12"

Your regex should match

"abc123"

Your regex should match

"astr1on11aut"

// tests completed

Thank you for responding ieahleen.

However I don’t quite understand your respond.

I thought the “\w” meant that the second and third characters could be numbers or letters. Am I incorrect?

your second lookahead is saying that second and third character of the string must be numbers

Does the second look ahead surpass the first lookahead?

they look from the same position and both have to match

ieahleen, THANK YOU SOOOO MUCH… you have helped me sooo much with that last statement. I was able to solve this particular problem and better understand “lookahead”(s) overall.

I am very grateful… you are my Yoda (smile)… smart you are!