Positive and negative lookaheads...with test case 12345

I am doing positive and negative lookaheads and I can’t understand the concept in itself…But still I tried my hands on this and it is not passing one test case…The code I did so far is given below

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

The following test case did not pass:

Your regex should not match the string

12345

i) can anyone explain what is positive and negative lookaheads in simple words
ii)what is the mistake i have made in my code??

What are the other test cases? That would be helpful to find out what your objective is. :slight_smile:

Lookahead/behind makes the engine to parse the string but to stay at the last position. Weird concept; only useful imo for “find something not followed by something else” (negative lookahead).

Practically, the engine parses the string until it finds the first match of the regEx-“rule”. Then it kind of “locks the position”, but keeps looking (ahead|behind), continuing trying to match its pattern against the string. Depending on your lookahead/behind-construct, it will evaluate positive and continue or negative and abort. If it evaluates positively, it will continue string evaluation from the previously locked position.

Best, Sebastian.

thanks a lot beiti…
I now have some idea on look aheads…its like giving multiple contions for choosing a pattern

the other test cases which are passed are:
Your regex should use two positive lookaheads .

Passed

Your regex should not match the string astronaut

Passed

Your regex should not match the string banan1

Passed

Your regex should match the string bana12

Passed

Your regex should match the string abc123

Your regex should not match the string 12345

Passed

Your regex should match the string 8pass99

Passed

Your regex should not match the string 1a2bcde

Passed

Your regex should match the string astr1on11aut

1

2

3

let sampleWord = “astronaut”;

let pwRegex = /(?=\w)(?=\d{2} *){5,}/; // Change this line

let result = pwRegex.test(sampleWord);

// running tests Your regex should not match the string

12345

Can u help me with this?? :slightly_frowning_face:

Most welcome! Happy if I could help. :slight_smile:

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