Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
{1}
at the end of the regex specifically makes it match only one instance, removing it will make this match all instances. I'm not sure if that's at all important within this context though, so it would make sense to check with those who added it in the first place.From looking at the git blame, this was added in the commit f9c95a4, authored by @ewosborne and merged by @zware 13 days ago. Let's wait on feedback from @zware before proceeding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even without the
{1}
it will match only one instance.for example we can check here https://regex101.com/r/xtB5yX/1 ( in fact in the explanation it says {1} is not needed )
removing the
{1}
does not have any effect on what will match.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you're correct, but it's always better to be on the safe side and double check with the core dev who added/approved of the previous version when making any code revisions, no matter how minor the changes are. Especially if the commit was made fairly recently and the core dev is currently active.
Either way though, a core developer still needs to approve and merge the PR before it can be added. IMO, the most well suited person for doing so would be @zware since he merged the PR that added this section. Alternatively, @serhiy-storchaka is the most active expert of the
re
module and has made several changes withinipaddress
.Edit: Also, thanks for the introduction to regex101. I've mostly used regexr in the past, but it's useful to know of a visual tool that supports the Python specific flavor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I was remembering incorrectly when I initially said:
For
re.match()
, it only matches at the beginning of the string, not each line. For matching all occurences,re.findall()
is used instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes that makes sense. let us wait for others to review this PR.
yeah I use regex101 to understand the regex visually than parsing it in my mind. it is an amazing tool.