Skip to content

regexUnnecessaryNestedAssertions

Reports trivially nested assertions in regular expressions that can be simplified.

✅ This rule is included in the ts logical presets.

Regular expression lookarounds are trivially nested when it contains exactly one element that is itself an assertion (anchor or another lookaround of the same direction). Such lookarounds are unnecessary and can be simplified. This rule reports those lookarounds.

const
const pattern: RegExp
pattern
= /(?=$)/;
const
const boundary: RegExp
boundary
= /(?=\b)/;
const
const pattern: RegExp
pattern
= /(?=(?=a))/;
const
const behind: RegExp
behind
= /(?<=(?<=a))/;
const
const pattern: RegExp
pattern
= new
var RegExp: RegExpConstructor
new (pattern: RegExp | string, flags?: string) => RegExp (+2 overloads)
RegExp
("(?=$)");
const
const boundary: RegExp
boundary
=
var RegExp: RegExpConstructor
(pattern: RegExp | string, flags?: string) => RegExp (+2 overloads)
RegExp
("(?=\\b)");

This rule is not configurable.

If you intentionally keep nested regular expression structures for code clarity or documentation purposes, you might prefer to disable this rule.

Made with ❤️‍🔥 around the world by the Flint team and contributors.