regexSuperLinearMoves
Reports quantifiers that can cause quadratic regex matching time.
✅ This rule is included in the ts logical presets.
When a quantifier at the start of a pattern is followed by elements that can fail to match, the regex engine may try the pattern from each position in the input string. For an input of length n, this can result in O(n²) time complexity.
This rule reports quantifiers that can cause quadratic regex matching time.
Examples
Section titled “Examples”Basic Quantifier with Literal Suffix
Section titled “Basic Quantifier with Literal Suffix”const pattern = /a*b/;const pattern = /^a*b/;Character Set Quantifier
Section titled “Character Set Quantifier”const pattern = /\s+foo/;const pattern = /^\s+foo/;Quantifier Inside Group
Section titled “Quantifier Inside Group”const pattern = /(?:\s*)foo/;const pattern = /^(?:\s*)foo/;RegExp Constructor
Section titled “RegExp Constructor”const pattern = new RegExp("a*b");const pattern = new RegExp("^a*b");Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your regex is only used on small trusted inputs where performance is not a concern, you might want to disable this rule. Some patterns are inherently super-linear but necessary for the matching logic. You might consider using Flint disable comments and/or configuration file disables for specific cases instead of completely disabling this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
regexp/no-super-linear-move