Skip to content

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.

const pattern = /a*b/;
const pattern = /\s+foo/;
const pattern = /(?:\s*)foo/;
const pattern = new RegExp("a*b");

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.