开发者

Match URL's which do NOT have a specific prefix

i match image urls inside a string with the following regular expression in javascript:

/\b(https?|ftp|file):\/\/[\-A-Z0-9+&@#\/%?=~_|!:,.;]*[\-A-Z0-9+&@#\/%=~_|]?(\.(jpe?g|png|gif))/ig

with the 开发者_运维百科String.replace function, i wrap all matches inside an -tag.

in a second step i'd like to match all urls, which do not have the above file extensions as prefix. my first intention was to use the ?!-operator like this:

/\b(https?|ftp|file):\/\/[\-A-Z0-9+&@#\/%?=~_|!:,.;]*[\-A-Z0-9+&@#\/%=~_|]?(?!\.(jpe?g|png|gif))/ig

unfortunatly, this does no work. tried different variations of this expression, but with now results.

thanks for any help in advance, manuel


Since you're asking about javascript, I think something like this could help :

var url_re = "\\b(https?|ftp|file):\\/\\/[\\-A-Z0-9+&@#\\/%?=~_|!:,.;]*[\\-A-Z0-9+&@#\\/%=~_|]?"
var re = new RegExp( "^(?!.*"+url_re+"\.(jpe?g|png|gif)).*"+url_re+"\.[a-z0-9_]+" , 'gi' )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜