Switch to regex module for URL identification
The URL detection regex was failing on input such as 0.1.2.3, as this
input triggered excessive back-tracking in the builtin re module.
The solution was to switch to the regex module, which behaves better.
Closes
from __future__ import unicode_literals
-import re
+import regex
# URL validation regex courtesy of: https://mathiasbynens.be/demo/url-regex
# A few minor mods to this regex to account for use cases represented in test_urls
@@ -45,6 +45,6 @@ _URL_PATTERN = (
r"$"
).strip()
-TOKEN_MATCH = re.compile(_URL_PATTERN, re.UNICODE).match
+TOKEN_MATCH = regex.compile(_URL_PATTERN, regex.UNICODE).match
__all__ = ['TOKEN_MATCH']
