Javascript regular expression for extracting Youtube video ids

后端 未结 4 1408
清酒与你
清酒与你 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:16

    The 1st regex is checking for "?v=GItD10Joaa0" when the url is something like "youtube.com/" and the 2nd is checking for "www.youtube.com/index?feature=youtu.be" when the url is "http://www.youtube.com/index?feature=youtu.be"

    So you can simply use the 1st regex if you want to get ids from 1st url and likewise :)

提交回复
热议问题