Skip to content

Instantly share code, notes, and snippets.

@fitoria
Created December 14, 2009 04:52
Show Gist options
  • Select an option

  • Save fitoria/255777 to your computer and use it in GitHub Desktop.

Select an option

Save fitoria/255777 to your computer and use it in GitHub Desktop.
def get_url(clean_update):
urlfinders = [
re.compile("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}|(((news|telnet|nttp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+)(:[0-9]*)?/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*[^]'\\.}>\\),\\\"]"),
re.compile("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}|(((news|telnet|nttp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+)(:[0-9]*)?"),
re.compile("(~/|/|\\./)([-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]|\\\\)+"),
re.compile("'\\<((mailto:)|)[-A-Za-z0-9\\.]+@[-A-Za-z0-9\\.]+"),
]
text = clean_update.raw_update.text
for finder in urlfinders:
if finder.search(text):
return finder.search(text).group()
else:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment