youtube链接的Reg exp [英] Reg exp for youtube link

查看:49
本文介绍了youtube链接的Reg exp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在开发的系统中,我需要识别以下格式的 youtube 链接

In a system that I'm developing I need to recognize the youtube link in the following format

[youtube]youtube 网址[/youtube]

[youtube]youtube url[/youtube]

暂时我想到了这个正则表达式:

for the moment I arrived at this regular expression:

#\[youtube\]http://www.youtube\.(.*)/watch\?v=([a-zA-Z0-9_-]*)\[\/youtube\]#s

但是这种模式无法识别像

But this pattern isn't able to recognize url like

[youtube]http://www.youtube.com/watch?v=s3wXkv1VW54&feature=fvst[/youtube]

注意 feature=fvst.

有人可以帮助我识别所有可能的 YouTube 网址吗?

Some one can help me in recognize all possible youtube url?

推荐答案

怎么样

|\[youtube\]http://www.youtube\.(.*?)/watch\?v=([a-zA-Z0-9_-]*)[%&=#a-zA-Z0-9_-]*\[\/youtube\]|s

更改正则表达式以仅将视频 ID 保留在括号内.

Changed the regex to keep only the video id inside parentheses.

这篇关于youtube链接的Reg exp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆