Skip to content

Instantly share code, notes, and snippets.

@timbroder
Last active December 15, 2015 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timbroder/5172690 to your computer and use it in GitHub Desktop.
Save timbroder/5172690 to your computer and use it in GitHub Desktop.
import re
def check(test_str):
pattern = r'(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?\xab\xbb\u201c\u201d\u2018\u2019]))'
if not re.search(pattern, test_str):
print 'Invalid : %r' % (test_str,)
else:
print 'Valid : %r' % (test_str,)
check("http://www.timbroder.com")
check("ht:a//hi.com")
check("http/a.hi.com")
check("www.hiadas.com")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment