RegexpGarden






















- Garden Text Representation
1234
let garden = "Rose\tRosemary\tPrimrose\t
Rose\tRose\tPrimrose\t
Rosemary\tRose\tRose\t
Rosemary\tRose";
- Code Editor
- Log
123456
garden = garden
.replace(//gi, "Blackberry");
Lesson task •
The rose should be replaced with blackberry if it is followed directly by NOT rosemary or by another rose that should be replaced
Negative Lookahead
(?!...) again
/x(?!y)/ matches "x" only if it is not directly followed by "y"Negative lookaheads, like Positive Lookaheads, can include nested capturing and non-capturing groups:
1234
console.log("foo foo foo foo 42".replace(/foo(?!(\s*foo\s*){2}42)/gi, "bar")) // bar foo bar bar 42
console.log("foo foo foo 42".replace(/foo(?!(\s*foo\s*){2}42)/gi, "bar")) // foo bar bar 42
console.log("foo foo 42".replace(/foo(?!(\s*foo\s*){2}42)/gi, "bar")) // bar bar 42
console.log("foo 42".replace(/foo(?!(\s*foo\s*){2}42)/gi, "bar")) // bar 42