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 pattern = /(?=$)/;
const boundary = /(?=\b)/;
const pattern = /(?=(?=a))/;
const behind = /(?<=(?<=a))/;
const pattern = new RegExp("(?=$)");
const boundary = 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 ❤️‍🔥 in Boston by Josh Goldberg and contributors.