Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

youtube link regex

Tags:

regex

php

youtube

im trying to make this work for all youtube links, which is working, except for youtube.com/v/videoid

only watch?v= is working with this regex, any assistance is greatful.

/http:\/\/(?:youtu\.be\/|(?:[a-z]{2,3}\.)?youtube\.com\/watch(?:\?|#\!)v=)([\w-]{11}).*/i
like image 380
chris mccoy Avatar asked Jan 27 '26 02:01

chris mccoy


2 Answers

The website Regular Expression Library is a good source for that. Try the following link: http://www.regexlib.com/Search.aspx?k=youtube

/((http:\/\/)?(?:youtu\.be\/|(?:[a-z]{2,3}\.)?youtube\.com\/v\/)([\w-]{11}).*|http:\/\/(?:youtu\.be\/|(?:[a-z]{2,3}\.)?youtube\.com\/watch(?:\?|#\!)v=)([\w-]{11}).*)/i
like image 23
Oli Avatar answered Jan 28 '26 18:01

Oli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!