I am trying to modify the following regex to enforce that the domain is either youtube
or youtu.be
. This original regex is meant to provide in the 2nd group the id of the video for watching.
E.g. lVIGhYMwRgs
my current test list
http://www.youtube.com/watch?v=lVIGhYMwRgs&feature=feedrec_grec_index
http://www.youtube.com/v/lVIGhYMwRgs?fs=1&hl=en_US&rel=0
http://www.youtube.com/watch?v=lVIGhYMwRgs#t=0m10s
http://www.youtube.com/embed/lVIGhYMwRgs?rel=0
http://www.youtube.com/watch?v=lVIGhYMwRgs
http://youtu.be/lVIGhYMwRgs
http://www.example.com/media/embed/83295164
First Regex
(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*)
The problem is that example.com
matches!
So I tried modifying the regex to the following to ensure either youtube
or youtu.be
are in the url:
((youtu.be\/)|(youtube.com\/))(v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*)
While this solves my
example.com
problem, it does not match the youtu.be
url.
I have also tried this regex because I think my problem is that youtu.be
only has a slash and then directly after, the id.
(youtube.com\/)(youtu.be|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*)
and then i tried this which works for youtu.be
and not much else.
((youtube.com\/)|(v\/|u\/\w\/|embed\/|watch\?v=|\&v=)|(youtu.be\/))([^#\&\?]*)
How can i fix my modification?