Regex match all url except youtube ones

霸气de小男生 提交于 2020-01-06 08:45:10

问题


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

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

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

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

thanks.

Help please.


回答1:


I would use the 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?

Edit: 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@:%_\+.~#?&\/\/=]+))

http://regexr.com?2u7gg



来源:https://stackoverflow.com/questions/6681070/regex-match-all-url-except-youtube-ones

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!