I want to match the video-ID from a vevo.com URL.
Example URL:
http://www.vevo.com/watch/arash/she-makes-me-go/SE2VJ1200401
The ID would be SE2VJ1200401
. I tried the pattern /(.*){12}
but that did not work.
I want to match the video-ID from a vevo.com URL.
Example URL:
http://www.vevo.com/watch/arash/she-makes-me-go/SE2VJ1200401
The ID would be SE2VJ1200401
. I tried the pattern /(.*){12}
but that did not work.
I think what you are probably aiming for is:
/(.{12})
But that will also match //www.vevo.c
and /watch/arash/
. If you want to limit it to just the last part of the URL, you could use:
/(.{12})$
However, you may want to consider using \w
(any word character) or \S
(any non-whitespace character) instead of .
For instance:
/(\w{12})$
/(\S{12})$
Those VEVO ids are actually part of a standard called the International Standard Recording Code, which has a strict formatting, which can help your regex be more specific.
One that I've used is this:
// 2 alphabetical chars, 3 alphanumeric, two digits, then 5 digits
var regex = /([A-Z]{2}[A-Z0-9]{3}\d{2}\d{5})/;
This also allows for URLs that end in a query string or a hash.