mirror of
https://github.com/alrayyes/wiki.git
synced 2024-12-01 15:26:23 +00:00
598 B
598 B
id | title |
---|---|
3ab00edf-6c63-4db2-b32e-d18f8d683329 | JavaScript Lookahead Assertions |
Examples
Positive lookahead assertion
Text after the current location must match the assertion
const RE_AS_BS = /aa(?=bb)/;
const match1 = RE_AS_BS.exec("aabb");
console.log(match1[0]); // 'aa'
Negative lookahead assertion
Text after the current location must not match the assertion
const RE_AS_NO_BS = /aa(?!bb)/;
console.log(RE_AS_NO_BS.test("aabb")); // false
console.log(RE_AS_NO_BS.test("aab")); // true
console.log(RE_AS_NO_BS.test("aac")); // true