pageClass | sidebarDepth | title | description | since |
---|---|---|---|---|
rule-details |
0 |
regexp/no-extra-lookaround-assertions |
disallow unnecessary nested lookaround assertions |
v1.11.0 |
💼 This rule is enabled in the ✅ plugin:regexp/recommended
config.
🔧 This rule is automatically fixable by the --fix
CLI option.
disallow unnecessary nested lookaround assertions
The last positive lookahead assertion within a lookahead assertion is the same without lookahead assertions. Also, The first positive lookbehind assertion within a lookbehind assertion is the same without lookbehind assertions. They can be inlined or converted to group.
/a(?=b(?=c))/u; /* -> */ /a(?=bc)/u;
/a(?=b(?=c|C))/u; /* -> */ /a(?=b(?:c|C))/u;
/(?<=(?<=a)b)c/u; /* -> */ /(?<=ab)c/u;
/(?<=(?<=a|A)b)c/u; /* -> */ /(?<=(?:a|A)b)c/u;
This rule aims to report and fix these unnecessary lookaround assertions.
/* eslint regexp/no-extra-lookaround-assertions: "error" */
/* ✓ GOOD */
var ts = 'JavaScript'.replace(/Java(?=Script)/u, 'Type');
var java = 'JavaScript'.replace(/(?<=Java)Script/u, '');
var re1 = /a(?=bc)/u;
var re2 = /a(?=b(?:c|C))/u;
var re3 = /(?<=ab)c/u;
var re4 = /(?<=(?:a|A)b)c/u;
/* ✗ BAD */
var ts = 'JavaScript'.replace(/Java(?=Scrip(?=t))/u, 'Type');
var java = 'JavaScript'.replace(/(?<=(?<=J)ava)Script/u, '');
var re1 = /a(?=b(?=c))/u;
var re2 = /a(?=b(?=c|C))/u;
var re3 = /(?<=(?<=a)b)c/u;
var re4 = /(?<=(?<=a|A)b)c/u;
Nothing.
This rule was introduced in eslint-plugin-regexp v1.11.0