我使用了优秀的gskinner.com/RegExr/工具来测试我的字符串匹配正则表达式,但我无法弄清如何将其实现到我的JavaScript文件中以返回true或false。
我目前的代码如下:
^(http:)\/\/(.+\.)?(stackoverflow)\.
在类似于
http://stackoverflow.com/questions/ask
的URL上,这将匹配(根据RegExr)http://stackoverflow.
所以这很棒,因为我想尝试将当前的window.location
与该字符串进行匹配,但是我遇到的问题是这个JavaScript脚本不起作用:var url = window.location;
if ( url.match( /^(http:)\/\/(.+\.)?(stackoverflow)\./ ) )
{
alert('this works');
};
你对我在这里做错了什么有什么想法吗?
感谢阅读。
Jannis
http://sub.domain.ext/
这一步? - Jannis