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

Fixes RE for IPv4 addresses #86

Merged
merged 1 commit into from
Jun 10, 2021

Conversation

kak-bo-che
Copy link

When the range of IPs are re.compiled the regex isn't greedy enough

>>> import re
>>> _ipv4_tld = ['.{}'.format(ip) for ip in reversed(range(256))]
>>> foo = re.compile('|'.join(_ipv4_tld))
>>> foo.findall('.81')
['.81']
>>> _ipv4_tld = ['.{}'.format(ip) for ip in range(256)]
>>> foo = re.compile('|'.join(_ipv4_tld))
>>> foo.findall('.81')
['.8']

When the range of IPs are re.compiled the regex isn't greedy enough

```python
>>> import re
>>> _ipv4_tld = ['.{}'.format(ip) for ip in reversed(range(256))]
>>> foo = re.compile('|'.join(_ipv4_tld))
>>> foo.findall('.81')
['.81']
>>> _ipv4_tld = ['.{}'.format(ip) for ip in range(256)]
>>> foo = re.compile('|'.join(_ipv4_tld))
>>> foo.findall('.81')
['.8']
```
@lipoja
Copy link
Owner

lipoja commented Jun 10, 2021

Thank you @kak-bo-che for this PR and your time spend on it! I really appreciate it.

And if you have any other ideas or improvement feel free to create issue or PR! :)
Have a nice day.
Jan

@lipoja lipoja merged commit eca7624 into lipoja:master Jun 10, 2021
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