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

resolving issue 93. finding valid ip address #96

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

devbazregari
Copy link

resolving issue 93. finding the valid IP address.
improving issue 93.

@fhightower
Copy link
Member

@devbazregari : I see you closed #94 - no harm done, but in the future, it would have been best to keep that PR open and make your updates on that PR. In that way, we can see the feedback (the PR reviews) and your improvements all in one place.

So I'm going to review this PR, but please keep this PR open and just make your updates on this PR. If you have any questions about this workflow, please let me know and I'm happy to clarify.

Copy link
Member

@fhightower fhightower left a comment

Choose a reason for hiding this comment

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

Thanks for updating this PR! Once you update your regex as described in the comment below, can you replace the one here with your regex? Then push your changes and we can see if the tests pass.

Thanks!


test_str = 'hi there 153,252,251,252'

pattern = re.compile(r"\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\,|$)){4}\b")
Copy link
Member

@fhightower fhightower Sep 27, 2022

Choose a reason for hiding this comment

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

Nice! Looks like you found a good way to remove duplicative content from the regex.

Looks like there's one more update needed. This regex will not properly handle strings like:

255,255,255,255 256,256,256,256

(I expect the regex to find 255,255,255,255 in 255,255,255,255 256,256,256,256, but it does not).

So we should modify the regex to this:

Suggested change
pattern = re.compile(r"\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\,|$)){4}\b")
pattern = re.compile(r"\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:,|\b)){4}")

Basically, I'm replacing $ with \b to capture any whitespace as the end of the regex. The (?:___) construct means this group is non-capturing (you can read more here).

@fhightower
Copy link
Member

Fixes #93

@fhightower
Copy link
Member

Hi @devbazregari : Are you still interested in working on this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants