Javascript regular expression for extracting Youtube video ids

后端 未结 4 1253
清酒与你
清酒与你 2021-01-15 05:35

The following code is used to get Youtube video ids in order to get a thumbnail image.

What is the reasoning behind the first regular expression and what is it doing

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-15 06:07

    Ok, I did some fishing around and came accross this regex. It should suit the purpose described above.

    youtu(?:\.be|be\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)
    

    From: C# regex to get video id from youtube and vimeo by url

    And: http://forrst.com/posts/Automatic_YouTube_Thumbnails_with_PHP_and_Regex-uta

提交回复
热议问题