[Analyzer]: Regex analyzers #68962
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Text.RegularExpressions
code-analyzer
Marks an issue that suggests a Roslyn analyzer
Milestone
There are some common misuses of Regex we could have analyzers for:
regex.Match(...).Success
should just beregex.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 whenRegexOptions.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 beregex.Count(...)
(e.g. https://grep.app/search?q=%5C.Matches%28.%2A%29%5C.Count®exp=true&filter[lang][0]=C%23)And potentially cases where we can easily detect the possibility of catastrophic backtracking and recommend RegexOptions.NonBacktracking.
The text was updated successfully, but these errors were encountered: