Regex for youtube URL

后端 未结 8 1397
囚心锁ツ
囚心锁ツ 2020-11-28 09:12

I am using the following regex for validating youtube video share url\'s.

var valid = /^(http\\:\\/\\/)?(youtube\\.com|youtu\\.be)+$/;
alert         


        
8条回答
  •  孤独总比滥情好
    2020-11-28 09:43

    I tried this one and it works fine for me.

    (?:http(?:s)?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'<> #]+)
    

    You can check here https://regex101.com/r/Kvk0nB/1

提交回复
热议问题