问题
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