正则表达式匹配字符串,直到whitespace Javascript
发布时间:2020-12-14 05:37:22 所属栏目:百科 来源:网络整理
导读:我希望能够匹配以下示例: www.example.comhttp://example.comhttps://example.com 我有以下正则表达式不匹配www.但会匹配http:// https://.我需要匹配上面示例中的任何前缀,直到下一个空格,从而整个URL. var regx = ((s))(http?://)|(https?://)|(ww
我希望能够匹配以下示例:
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]+ 这是online demo 示例代码: 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) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |