Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.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
javascript-String.Match()未按预期工作_Javascript_Regex_String - Fatal编程技术网

javascript-String.Match()未按预期工作

javascript-String.Match()未按预期工作,javascript,regex,string,Javascript,Regex,String,使用以下字符串: https://plus.google.com/?gpsrc=ogpy0&tab=wX http://www.google.com.ar/imghp?hl=es&tab=wi http://news.google.com.ar/nwshp?hl=es&tab=wn https://mail.google.com/mail/?tab=wm http://books.google.com.ar/bkshp?hl=es&tab=wp http://www.google.co

使用以下字符串:

https://plus.google.com/?gpsrc=ogpy0&tab=wX http://www.google.com.ar/imghp?hl=es&tab=wi http://news.google.com.ar/nwshp?hl=es&tab=wn https://mail.google.com/mail/?tab=wm http://books.google.com.ar/bkshp?hl=es&tab=wp http://www.google.com.ar/blogsearch?hl=es&tab=wb https://docs.google.com/?tab=wo http://groups.google.com.ar/grphp?hl=es&tab=wg http://www.google.com.ar/intl/es/options/ http://www.google.com.ar/preferences?hl=es http://www.google.com.ar/advanced_search?hl=es-419 http://www.google.com/history/optout?hl=es http://www.google.com.ar/support/websearch/bin/answer.py?answer=186645&form=bb&hl=es-419 http://www.google.com.ar/services/ https://plus.google.com/112209395112018703654 http://www.google.com/ncr javascript:void(0)

这个正则表达式:

(http://)(www.){0,1}(google.com.ar)[\S]*

此代码:

var result = links.match(new RegExp("(http://)(www.){0,1}(google.com.ar)[\S]*"));
for(var i = 0;i<result.length;i++)
{
    alert(result[i]);
}
var result=links.match(新的RegExp(“(http://)(www.){0,1}(google.com.ar)[\S]*”);

对于(var i=0;i使用正则表达式上的
g
标志

var result = links.match(/http:\/\/(?:www\.)?google\.com\.ar([\S]*)/g);

…你期望什么事情没有发生?”…没有按预期工作“你到底期望什么?我期望正确的匹配,例如正则表达式应该至少匹配:但它没有做到这一点。谢谢,这非常有效。但我需要网页成为一个变量,有没有办法用正则表达式“格式”存档此内容我发布了?好吧,如果你在
结果
数组中循环,你可以再次测试正则表达式,但不需要
g
标志。这将允许你获得子模式。这就是我的意思:新的正则表达式(“(http://)(www.){0,1}(+URL+”[\S]*”)。我需要一种更简单的方法从任何网站获取链接(不包括子域:)。谢谢,我将你的模式一分为二:http:\/\\/(?:www\\)([\\S]*),然后选中:links.match(新的RegExp(pattern1+URL+pattern2,'gi');