pageClass | sidebarDepth | title | description | since |
---|---|---|---|---|
rule-details |
0 |
regexp/prefer-predefined-assertion |
prefer predefined assertion over equivalent lookarounds |
v0.10.0 |
💼 This rule is enabled in the ✅ plugin:regexp/recommended
config.
🔧 This rule is automatically fixable by the --fix
CLI option.
prefer predefined assertion over equivalent lookarounds
All predefined assertions (\b
, \B
, ^
, and $
) can be expressed as lookaheads and lookbehinds. E.g. /a$/
is the same as /a(?![^])/
.
In most cases, it's better to use the predefined assertions because they are better known.
/* eslint regexp/prefer-predefined-assertion: "error" */
/* ✓ GOOD */
var foo = /a(?=\W)/;
/* ✗ BAD */
var foo = /a(?![^])/;
var foo = /a(?!\w)/;
var foo = /a+(?!\w)(?:\s|bc+)+/;
Nothing.
This rule was introduced in eslint-plugin-regexp v0.10.0