regexp for detect that the url doesn´t end with an extension

Posted by devnieL on Stack Overflow See other posts from Stack Overflow or by devnieL
Published on 2011-03-01T15:07:44Z Indexed on 2011/03/01 15:24 UTC
Read the original article Hit count: 209

Filed under:
|
|

Hello. I'm using this regular expression for detect if an url ends with a jpg :

var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]*^\.jpg)/ig;

it detects the url : e.g. http://www.blabla.com/sdsd.jpg

but now i want to detect that the url doesn't ends with an jpg extension, i try with this :

var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]*[^\.jpg]\b)/ig;

but only get http://www.blabla.com/sdsd

then i used this :

var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]*[^\.jpg]$)/ig;

it works if the url is alone, but dont work if the text is e.g. :

http://www.blabla.com/sdsd.jpg text

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html