正则表达式匹配除了YouTube的所有网址 [英] Regex match all url except youtube ones

查看:667
本文介绍了正则表达式匹配除了YouTube的所有网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信这是一个琐碎的问题,你这里的genii。我似乎被困住了

I am sure this is a trivial questions for you genii here. I seem to be stuck

我有几个链接要处理,我想将所有链接转换为超链接和youtube链接到YouTube视频。

I have a couple of links to process and I want to convert all links to hyperlinks and youtube links to youtube videos.

我有一切工作。我只需要弄清楚如何regex出所有链接 EXCEPT youtube。

I have everything working. I just need to figure out how to regex out all links EXCEPT youtube ones.

这是一个我的正则表达式的例子: http://gskinner.com/RegExr/?2u7g4

Here is an example of my regex: http://gskinner.com/RegExr/?2u7g4

感谢。

请帮助。

推荐答案

regex:

/(http:\/\/)?(www\.)?youtube.com\S*/

或者你是说你想要添加在正则表达式的顶部?

to match youtube links. Or did you mean you wanted to add on top of the regex you already have?

编辑:哦,我是哑的,写的东西超长,是的,只是负在比赛开始时先行:

Oh, I'm dumb and wrote something super long, yeah, just negative lookahead at the beginning of your match:

(?!\S+youtube\.com)((?<!\S)(((f|ht){1}tp[s]?:\/\/|(?<!\S)www\.)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+))


$ b b

http://regexr.com?2u7gg

这篇关于正则表达式匹配除了YouTube的所有网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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