Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Analyzer]: Regex.Match(...).Success to Regex.IsMatch #111238

Open
stephentoub opened this issue Jan 9, 2025 · 1 comment
Open

[Analyzer]: Regex.Match(...).Success to Regex.IsMatch #111238

stephentoub opened this issue Jan 9, 2025 · 1 comment
Labels
api-ready-for-review API is ready for review, it is NOT ready for implementation area-System.Text.RegularExpressions code-analyzer Marks an issue that suggests a Roslyn analyzer code-fixer Marks an issue that suggests a Roslyn code fixer

Comments

@stephentoub
Copy link
Member

I see a non-trivial amount of code that does Regex.Match(...).Success rather than Regex.IsMatch(...). The latter is functionally equivalent but more efficient, as it doesn't need to compute full match boundaries, doesn't need to compute capture groups, and doesn't need to allocate a Match object and supporting data structures. We should have an analyzer that looks for the former and a fixer that translates it into the latter. It should apply to both instance and static methods, everywhere there's a Match overload with arguments that have an exactly corresponding IsMatch overload.

@stephentoub stephentoub added api-ready-for-review API is ready for review, it is NOT ready for implementation area-System.Text.RegularExpressions code-analyzer Marks an issue that suggests a Roslyn analyzer code-fixer Marks an issue that suggests a Roslyn code fixer labels Jan 9, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jan 9, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions
See info in area-owners.md if you want to be subscribed.

@stephentoub stephentoub removed the untriaged New issue has not been triaged by the area owner label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-ready-for-review API is ready for review, it is NOT ready for implementation area-System.Text.RegularExpressions code-analyzer Marks an issue that suggests a Roslyn analyzer code-fixer Marks an issue that suggests a Roslyn code fixer
Projects
None yet
Development

No branches or pull requests

1 participant