There are some common misuses of Regex we could have analyzers for: - `regex.Match(...).Success` should just be `regex.IsMatch(...)` (e.g. https://grep.app/search?q=%5C.Match%28.%2A%29%5C.Success®exp=true&filter[lang][0]=C%23) - `RegexOptions.CultureInvariant` is specified when `RegexOptions.IgnoreCase` isn't specified and the pattern doesn't contain `(?i)` (e.g. https://grep.app/search?q=%22%2C%20RegexOptions.CultureInvariant%5C%29®exp=true&filter[lang][0]=C%23) We can also flag cases where new Regex APIs would be useful: - `regex.Matches(...).Count` should just be `regex.Count(...)` (e.g. https://grep.app/search?q=%5C.Matches%28.%2A%29%5C.Count®exp=true&filter[lang][0]=C%23) - Use of Match but only ever using Index/Length could potentially use the new EnumerateMatches; this one is harder. And potentially cases where we can easily detect the possibility of catastrophic backtracking and recommend RegexOptions.NonBacktracking.
Activity
stephentoub commentedon Jan 9, 2025
Opened individual issues instead