Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

Latest commit

 

History

History
35 lines (24 loc) · 1.01 KB

no-trivially-nested-quantifier.md

File metadata and controls

35 lines (24 loc) · 1.01 KB

no-trivially-nested-quantifier 🔧

Disallow nested quantifiers that can be rewritten as one quantifier.

configuration in plugin:clean-regex/recommended: "warn"

Source file
Test file

Description

In some cases, nested quantifiers can be rewritten as one quantifier (e.g. (?:a{1,2}){3} -> a{3,6}).

The rewritten form is simpler and cannot cause exponential backtracking (e.g. (?:a{1,2})+ -> a+).

Examples

Examples of valid code for this rule:

/(a{1,2})+/  // the rule won't touch capturing groups
/(?:a{2})+/

Examples of invalid code for this rule:

/(?:a{1,2})+/     // == /a+/
/(?:a{1,2}){3,4}/ // == /a{3,8}/
/(?:a{4,}){5}/    // == /a{20,}/