Jquery url的正则表达式
我正在使用urlJquery url的正则表达式,jquery,Jquery,我正在使用url/\b(http | https)?(:\/\/)?(\S*)\(\w{1,45})/ig 但如果url更大,则不验证。它的工作范围达到了延伸的一半。如果我在url后面尝试另一个正则表达式,并在其中加上空格,则该正则表达式将作为包含word的完整url。您能帮助我吗?如果您想从一个文本块中提取URL,可以使用以下regexp: / http // Match literal http s? // Match 's' zero or one time :\/
/\b(http | https)?(:\/\/)?(\S*)\(\w{1,45})/ig
但如果url更大,则不验证。它的工作范围达到了延伸的一半。如果我在url后面尝试另一个正则表达式,并在其中加上空格,则该正则表达式将作为包含word的完整url。您能帮助我吗?如果您想从一个文本块中提取URL,可以使用以下regexp:
/
http // Match literal http
s? // Match 's' zero or one time
:\/\/ // Match literal ://
[^\s]+ // Match everything but spaces, tabs & newlines one or more times
/g
这也将匹配:https://localhost
和https://a
var str = 'text here https://example.com/john.doe some more text and http://another.link.example.com/with?query=string';
str.match(/https?:\/\/[^\s]+/g) // ["https://example.com/john.doe", "http://another.link.example.com/with?query=string"]
如果要验证url是否以http或https开头,是否可以提供一些示例数据?
^https?://
。这与jQuery无关