Created
May 8, 2015 02:20
-
-
Save CodyKochmann/e315cf561a42c88a7426 to your computer and use it in GitHub Desktop.
python snippet to check or verify if the input string is a link.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_if_link(s,req_http=True): | |
# Checks if the input is a link. | |
allowed_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=%" | |
if req_http and "http" not in s: | |
return(False) | |
if "://" in s: | |
for i in s: | |
if i not in allowed_chars: | |
return(False) | |
return(True) | |
return(False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment