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.
β Pull Requests not made with this template will be automatically closed π₯
Prerequisites
Why do we need this pull request?
This should fix a few issues we were seeing with URLs. I have went through the regex and modified some parts. There may still be some cases but with this changes I saw a lot better results.
Also added more
Examples
andhttps://www.google.com
now matches fully.I have written an explanation for regex from start of the URL till the end to make it easier and quicker to review. Also give feedback, so it can get even better. :)
(?i)(?:(?:https?|ftp):\/\/)?(?:\S+:\S+@)?(?:[a-z0-9-_~]+\.)*[a-z0-9-]{1,62}\.(?:COM|IO|BLOG|ORG|TECH)(?::\d{2,5})?(?:\/[a-z0-9-_~.]+)*(?:[?#]\S*)*\/?
http
/https
/ftp
is still optional at the beggining.[a-z0-9-_~]
with.
in-between. Previously this part was matched as whole which caused something likewwww.....google.com
to be valid.[a-z0-9-]
and is 1-62 characters long.[a-z0-9-_~.]
with/
in-between.?
or#
characters it basically matches to everything after it until there is a space or line break. I do not think this characters can get any more limited.What GitHub issues does this fix?
Copy / paste of output
Please copy and paste the output of PyWhat with your new addition using an example that tests this addition below: