Two positive lookaheads

hi I am new here this is my first ever post on i been searching for this problem but i didn’t find it anywhere in this challenge i only want to know what is the meaning of
two parenthesis (?=)(?=) i know both are positive lookaheads but can someone explain to me what if i write this regex (?=\w{3,6})(?=\d) isn’t that mean that lookahead for aleast 3 to 6 char’s and 1 digit. but when my string = “aaa1”; that is false .

i just want to know what is the meaning to these two lookaheads

please thank you.

Regex traverses string with the cursor, just like you would do in text editor. Let’s examine string 'aaa1' with cursor (|):

/** Position 0 */
|aaa1
// Look ahead for 3-6 alphanumeric characters: CHECK
// Look ahead for digit: FAIL (it is "a" ahead)

/** Position 1 */
a|aa1
// Look ahead for 3-6 alphanumeric characters: CHECK
// Look ahead for digit: FAIL (it is "a" ahead)

/** Position 2 */
aa|a1
// Look ahead for 3-6 alphanumeric characters: FAIL
// Look ahead for digit: FAIL (it is "a" ahead)

/** Position 3 */
aaa|1
// Look ahead for 3-6 alphanumeric characters: FAIL
// Look ahead for digit: CHECK

As you can see there is no such case where both lookaheads are successful. Hopefully this will help :slight_smile:

1 Like

Sir, Thank you very much .I been looking this kind of explanation now i understand both lookaheads are being checked at the same position.Sometimes it is impossible to have a
alphabet and number is the same position that was my confusion for last two days.

now i understand that:

let str = “abc123”;
let regex = /(?=\w{3,6})(?=\d)/;
console.log(str.match(regex)) // [ ‘’, index: 3, input: ‘abc123’, groups: undefined ]

it is matching in position or index 3 because there are 3 char’s and digit.

thank’s again .