Skip to content

Conversation

@stephentoub
Copy link
Member

  • Use IsMatch instead of Match(...).Success
  • Use EnumerateMatches when Index/Length are needed but not captures
  • Remove Regex that could just be IndexOf
  • Regex.Match never returns null, so remove null checks

@ghost
Copy link

ghost commented May 6, 2022

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@ghost
Copy link

ghost commented May 6, 2022

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

Issue Details
  • Use IsMatch instead of Match(...).Success
  • Use EnumerateMatches when Index/Length are needed but not captures
  • Remove Regex that could just be IndexOf
  • Regex.Match never returns null, so remove null checks
Author: stephentoub
Assignees: stephentoub
Labels:

area-System.Text.RegularExpressions

Milestone: -

Copy link
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a small comment but looks good otherwise. I wonder if we should add another analyzer that suggests IsMatch for people that are only doing Match().Success

@joperezr
Copy link
Member

joperezr commented May 6, 2022

Lol just saw you logged #68962 this morning, so that covers my comment about probably wanting an analyzer 😆

- Use IsMatch instead of Match(...).Success
- Use EnumerateMatches when Index/Length are needed but not captures
- Remove Regex that could just be IndexOf
@stephentoub stephentoub merged commit 20120e0 into dotnet:main May 14, 2022
@stephentoub stephentoub deleted the improveregexusage branch May 14, 2022 21:55
@ghost ghost locked as resolved and limited conversation to collaborators Jun 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants