tags:

views:

47

answers:

2

Does someone have a regular expression that gets a link to a Youtube video (not embedded object) from (almost) all the possible ways of linking to Youtube?

I think this is a pretty common problem and I'm sure there are a lot of ways to link that.

A starting point would be:

A: 

It'd be the longest RegEx in the world if you managed to cover all link formats, but here's one to get you started which will cover the first couple of link formats:

http://(www\.)?youtube\.com/watch\?.*v=([a-zA-Z0-9]+).*

The second group will match the video ID if you need to get that out.

TimS
A: 

So far I got this Regular expression working for the examples I posted, and it gets the ID on the first group:

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