var url_pattern = new RegExp("(?:http| https)://(www.|.*)someurlhere[.]com/\d\d\d\d/\d\d/\d\d/.*/", "i");
var url=window.location; //or could be document.URL both don't work
url.match(url_pattern);
爲什麼它返回null,或不確定的,但是當我扔的正則表達式爲檢查工作完美的,我只是想確保URL匹配JavaScript的正則表達式匹配返回null或undefined
值得注意的是,window.location實際上是一個對象。位置上定義了許多可用和有用的屬性。請參閱:https://developer.mozilla.org/en/DOM/window.location –
我添加到對象的toString(),它仍然給我一個NULL返回 – italiano40
@PeterWagenet - 使用window.location需要一個字符串的上下文會自動調用toString(),它會給你完整的URL。如果這是你想要的,可能更好地使用'.href' proeprty,但是在大多數情況下都可以。 – jfriend00