Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for skipping specified URL extensions

Tags:

regex

I have a link. Ex: http://my.domain/url.jsp

My goal is create patter that will be not allow any URLs with extension like this: .ex1, .ex2, .ex3

I was searching a long of time and find some approach, but it's really opposite that I want.

([^\s]+(\.(?i)(ex1|ex2|ex3))$) 
like image 715
fashuser Avatar asked Oct 03 '22 10:10

fashuser


1 Answers

If lookbehind is supported then this regex should work:

^\S+$(?<!\.(?:ex1|ex2|ex3)$)

Live Demo: http://www.rubular.com/r/gQDxYdDKcU

If lookbehind isn't supported (e.g. Javascript) then use this lookahead based regex:

^(?!.*?\.(?:ex1|ex2|ex3)$)\S+$

Live Demo: http://www.rubular.com/r/S0FGAETLr2

like image 170
anubhava Avatar answered Oct 07 '22 18:10

anubhava