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 · 2 comments · May be fixed by dotnet/roslyn-analyzers#7547
Open

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

stephentoub opened this issue Jan 9, 2025 · 2 comments · May be fixed by dotnet/roslyn-analyzers#7547
Assignees
Labels
api-approved API was approved in API review, it can be implemented 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 in-pr There is an active PR which will close this issue when it is merged
Milestone

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
@ericstj ericstj added this to the 10.0.0 milestone Jan 13, 2025
@terrajobst
Copy link
Contributor

terrajobst commented Jan 21, 2025

Video

  • Looks good as proposed
    • Severity: Suggestion
    • Category: Performance

@terrajobst terrajobst added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for review, it is NOT ready for implementation labels Jan 21, 2025
@stephentoub stephentoub added the in-pr There is an active PR which will close this issue when it is merged label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved API was approved in API review, it can be implemented 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 in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants