youtube链接的正则表达式 [英] Regular expression for youtube links
本文介绍了youtube链接的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有人有一个正则表达式可以从(几乎)所有可能的链接到 Youtube 的方式中获取指向 Youtube 视频(不是嵌入对象)的链接?
Does someone have a regular expression that gets a link to a Youtube video (not embedded object) from (almost) all the possible ways of linking to Youtube?
我认为这是一个非常普遍的问题,我相信有很多方法可以将其联系起来.
I think this is a pretty common problem and I'm sure there are a lot of ways to link that.
起点是:
- http://www.youtube.com/watch?v=iwGFalTRHDA
- http://www.youtube.com/watch?v=iwGFalTRHDA&功能=相关
- http://youtu.be/iwGFalTRHDA
- http://youtu.be/n17B_uFF4cA
- http://www.youtube.com/embed/watch?feature=player_embedded&v=r5nB9u4jjy4
- http://www.youtube.com/watch?v=t-ZRX8984sc
- http://youtu.be/t-ZRX8984sc
- ...请添加更多可能的链接和/或正则表达式来检测它们.
推荐答案
到目前为止,我让这个 Regular expression
适用于我发布的示例,并且它获得了第一组的 ID:>
So far I got this Regular expression
working for the examples I posted, and it gets the ID on the first group:
http(?:s?):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-\_]*)(&(amp;)?[\w\?=]*)?
这篇关于youtube链接的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文