embed_url = 'http://www.vimeo.com/52422837'
response = re.search(r'^(http://)?(www\.)?(vimeo\.com/)?([\/\d+])', embed_url)
return response.group(4)
The response is:
5
I was hoping for
52422837
Anybody an idea? I'm really bad with regexes :S
Don't reinvent the wheel!
>>> import urlparse
>>> urlparse.urlparse('http://www.vimeo.com/52422837')
ParseResult(scheme='http', netloc='www.vimeo.com', path='/52422837', params='',
query='', fragment='')
>>> urlparse.urlparse('http://www.vimeo.com/52422837').path.lstrip("/")
'52422837'
Use \d+
(no brackets) to match the literal slash + digits:
response = re.search(r'^(http://)?(www\.)?(vimeo\.com/)?(\d+)', embed_url)
Result:
>>> re.search(r'^(http://)?(www\.)?(vimeo\.com/)?(\d+)', embed_url).group(4)
'52422837'
You were using a character group ([...]
) where none was needed. The pattern [\/\d+]
matches exactly one of /
, +
or a digit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With