At the moment I'm using this regex to extract the video id from a Youtube URL:
url.match(/v=([^&]*)/)[1]
How can I alter this so that it will also get the video id from this Youtube URL, which has no v parameter:
http://www.youtube.com/user/SHAYTARDS#p/u/9/Xc81AajGUMU
Thanks for reading.
EDIT: I'm using ruby 1.8.7
There's no need to use regular expression
should work in this case. This will match anything that follows the last slash in a string, so of course it would match a lot more than just Youtube video ids. From your question I'm inferring that you already know whether a link is a Youtube link or not (since your regex is also quite unspecific), but if you don't, try
Unless you're on Ruby 1.9, you can't do it in a single regex because Ruby 1.8 doesn't support lookbehind.
For Ruby 1.8.7 this will do it.