正则表达式匹配图像 URL
我正在尝试获取一个简单的正则表达式来验证 URL 是否包含结尾数字
var testRegex = /^https?:\/\/(?:[a-z\-]+\.)+[a-z]{2,6}(?:\/[^\/#?]+)+\.(?:jpe?g|gif|png)$/;
var imageUrl = "http://stackoverflow.com/questions/406192/how-to-get-the-current-url-in-jquery";
if (testRegex.test(imageUrl)) {
alert('Not Match');
}
,这应该触发alert('Not Match');
,但事实并非如此?请参阅 http://jsfiddle.net/UgfKn/
发生了什么事?
I am trying to get a simple regex to verify that a URL contains the ending figures
var testRegex = /^https?:\/\/(?:[a-z\-]+\.)+[a-z]{2,6}(?:\/[^\/#?]+)+\.(?:jpe?g|gif|png)$/;
var imageUrl = "http://stackoverflow.com/questions/406192/how-to-get-the-current-url-in-jquery";
if (testRegex.test(imageUrl)) {
alert('Not Match');
}
And this should trigger alert('Not Match');
and it doesn't ? See http://jsfiddle.net/UgfKn/
What's going on ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的意思是:
do you mean:
如果
testRegex
匹配,testRegex.test
将计算为 True。IE
testRegex.test
will evaluate to True iftestRegex
DOES match.ie
if 条件中缺少
!
请参阅
http://jsfiddle.net/UgfKn/1/
You are missing
!
in the if conditionSee
http://jsfiddle.net/UgfKn/1/