Skip to content

Instantly share code, notes, and snippets.

@rvill
Last active August 29, 2015 14:08
Show Gist options
  • Save rvill/d759d75a476c0a205573 to your computer and use it in GitHub Desktop.
Save rvill/d759d75a476c0a205573 to your computer and use it in GitHub Desktop.
Grab image id from flickr URL with regular expression in python
url = 'https://farm4.staticflickr.com/3943/15386021170_c2607cb639_z.jpg'
#\d+ match digits; \D+ match a non-digit which is "/" after the 1st 4 digits; (d\+) get the last set of digits, in group(6)
re.search(r'^(https://)?(farm4\.)?(staticflickr\.com/)?(\d+)?(\D+)(\d+)',url).group(6)
#returns 15386021170
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment