我希望能够匹配以下示例:
www.example.com http://example.com https://example.com
我有以下正则表达式不匹配www.但会匹配http:// https://.我需要匹配上面示例中的任何前缀,直到下一个空格,从而整个URL.
var regx = ((\s))(http?:\/\/)|(https?:\/\/)|(www\.)(?=\s{1});
假设我有一个如下所示的字符串:
我在www.stackoverflow.com和那里的人们那里找到了很多帮助!
我想在该字符串上运行匹配并获取
www.stackoverflow.com
谢谢!
解决方法
你可以试试
(?:www|https?)[^\s]+
示例代码:
var str="I have found a lot of help off www.stackoverflow.com and the people on there!"; var found=str.match(/(?:www|https?)[^\s]+/gi); alert(found);
模式说明:
(?: group,but do not capture: www 'www' | OR http 'http' s? 's' (optional) ) end of grouping [^\s]+ any character except: whitespace (\n,\r,\t,\f,and " ") (1 or more times)