繁体   English   中英

正则表达式匹配图像URL

[英]Regex to match Image 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/

这是怎么回事 ?

你的意思是:

if (!testRegex.test(imageUrl)) {
  alert('Not Match');
}

如果testRegex匹配, testRegex.test将评估为True。

if (testRegex.test(imageUrl)) {
  alert('Match');
} else {
  alert('Not match');
}

你错过了! 在if条件下

if ( ! testRegex.test(imageUrl1) ) {
    alert('Not Match');
}

http://jsfiddle.net/UgfKn/1/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM