使用下面的字符串不工作:的JavaScript String.Match()如預期
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 &標籤= 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:// gro ups.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:無效(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://www.google.com.ar
- 的http://
- WWW。
- google.com.ar
我已經試圖測試正則表達式中http://regexpal.com/和www.regextester.com,並在這兩種情況下高亮匹配是正確的,所以我想這個問題是與代碼。 我真的很新的JavaScript,所以我不能看到問題。
在此先感謝
......你在期待什麼沒有發生? – Amber
「......沒有按預期工作」你期望的**是什麼**? –
我預計正確的匹配,例如正則表達式應至少匹配:http://www.google.com.ar/intl/es-419/about.html 但它不這樣做。 – BizTuk