正则表达式匹配图像 URL
问题描述:
我正在尝试使用一个简单的正则表达式来验证 URL 是否包含结尾数字
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://*.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/
And this should trigger alert('Not Match');
and it doesn't ? See http://jsfiddle.net/UgfKn/
这是怎么回事?
答
你的意思是:
if (!testRegex.test(imageUrl)) {
alert('Not Match');
}