Используя следующую строку:
http://www.google.com.ar/setprefs?prev=http://www.google.com.ar/&sig=0_Kxz_cp1G52p8pcrDBlMIQhwJAL0%3D&suggon=2 https://plus.google.com/?gpsrc=ogpy0&tab=wX http://www.google.com.ar/webhp?hl=es&tab=ww http://www.google.com.ar/imghp?hl=es&tab=wi http://video.google.com.ar/?hl=es&tab=wv http://news.google.com.ar/nwshp?hl=es&tab=wn http://translate.google.com.ar/?hl=es&tab=wT https://mail.google.com/mail/?tab=wm http://www.google.com.ar/intl/es/options/ http://books.google.com.ar/bkshp?hl=es&tab=wp http://scholar.google.com.ar/schhp?hl=es&tab=ws http://www.google.com.ar/blogsearch?hl=es&tab=wb https://www.google.com/calendar?tab=wc https://docs.google.com/?tab=wo https://sites.google.com/?tab=w3 http://groups.google.com.ar/grphp?hl=es&tab=wg http://www.google.com.ar/reader/?hl=es&tab=wy http://www.google.com.ar/intl/es/options/ https://accounts.google.com/ServiceLogin?hl=es&continue=http://www.google.com.ar/ http://www.google.com.ar/preferences?hl=es http://www.google.com.ar/preferences?hl=es-419 http://www.google.com.ar/advanced_search?hl=es-419 http://www.google.com.ar/language_tools?hl=es-419 http://www.google.com/history/optout?hl=es http://www.google.com.ar/webhp?hl=es-419 http://www.google.com.ar/support/websearch/bin/answer.py?answer=186645&form=bb&hl=es-419 http://www.google.com.ar/intl/es-419/ads/ http://www.google.com.ar/services/ http://www.google.com.ar/intl/es-419/privacy.html https://plus.google.com/112209395112018703654 http://www.google.com.ar/intl/es-419/about.html 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]); }
Дает мне этот вывод:
Я уже пытался протестировать регулярное выражение в http://regexpal.com/ и www.regextester.com, и в обоих случаях выделенные совпадения верны, поэтому я полагаю, что проблема с кодом. Я действительно новичок в JavaScript, поэтому я не вижу проблемы.
Заранее спасибо
Используйте флаг g на своем регулярном выражении.
g
var result = links.match(/http:\/\/(?:www\.)?google\.com\.ar([\S]*)/g);