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

Latest commit

 

History

History
29 lines (20 loc) · 1.34 KB

optimal-concatenation-quantifier.md

File metadata and controls

29 lines (20 loc) · 1.34 KB

optimal-concatenation-quantifier 🔧

Use optimal quantifiers for concatenated quantified characters.

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

Source file
Test file

Description

If two quantified characters, character classes, or characters are concatenated, the quantifiers can be optimized if either of the characters elements is a subset of the other.

Let's take \d+\w+ as an example. This can be optimized to the equivalent pattern \d\w+. Not only is the optimized pattern simpler, it is also faster because the first pattern might take up to O(n^2) steps to fail while the optimized pattern will fail after at most O(n) steps. Generally, the optimized pattern will take less backtracking steps to fail.

Choosing optimal quantifiers does not only make your patterns simpler but also faster and most robust against ReDos attacks.

fixable: boolean

With this option you can control whether reported issue will be auto-fixable. You might want to turn the fixability off because the optimally-quantified pattern does not express your intend.