[removed] extract URLs from string (inc. querystring) and return array

前端 未结 4 1236
臣服心动
臣服心动 2020-12-01 23:44

I know this has been asked a thousand times before (apologies), but searching SO/Google etc I am yet to get a conclusive answer.

Basically, I need a JS function whic

4条回答
  •  醉梦人生
    2020-12-02 00:31

    You could use the regex from URI.js:

    // gruber revised expression - http://rodneyrehm.de/t/url-regex.html
    var uri_pattern = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/ig;
    

    String#match and or String#replace may help…

提交回复
热议问题