Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery url的正则表达式_Jquery - Fatal编程技术网

Jquery url的正则表达式

Jquery 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 :\/

我正在使用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
  :\/\/  // 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无关