-3

Admittedly, Regular Expressions are not my strong point. I found a regex for YouTube videos online and used it.

(http://)?(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)(\w*)(&(amp;)?[\w\?=]*)?

However, several of the YouTube links attempted are not working. Here's an example of a URL that fails on this Regex

http://www.youtube.com/user/SWCCAC?feature=mhee#p/u/98/DuAqY5nQ7k0

Can anyone help me with a Regex that will work with all YouTube videos, but ONLY YouTube links are allowed.

Thanks

Mark Highfield
  • 443
  • 3
  • 9
  • 24
  • http://stackoverflow.com/questions/8306963/regular-expression-youtube-url –  May 22 '13 at 18:03
  • http://stackoverflow.com/questions/13476060/validating-youtube-url-using-regex –  May 22 '13 at 18:03
  • http://stackoverflow.com/questions/7654542/youtube-url-regex –  May 22 '13 at 18:03
  • https://www.google.com/search?q=youtube+URL+regular+expression&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a –  May 22 '13 at 18:04
  • sorry, none of those other links worked with all my examples, which is why I posted again here. -3 voting too, tough crowd. I'll keep googling it then I guess – Mark Highfield May 22 '13 at 19:45

1 Answers1

-1

I think we need a clearer idea of what youtube URLs can look like. Judging by the regex you gave, there are several possibilities besides your example. The one you posted is for a user, not a video - do you want to include user URLs as well?

David Knipe
  • 3,417
  • 1
  • 19
  • 19
  • what do you mean a user? The client gave me that link as a YouTube link that wasn't allowed, does that mean they were logged in or something? – Mark Highfield May 23 '13 at 19:00
  • That was the page for a user (South West CCAC), not a video. It plays a video when you go to the page, certainly. That's probably just the most recent video by that user, or the first one they put in their list of featured videos, or something. The actual video in question is (currently) http://www.youtube.com/watch?v=g1uNzhMSsK8 , but the video on the user page probably changes regularly, so it's a bad idea to give that link as a link to a video. – David Knipe May 27 '13 at 15:42