4

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))$) 
2
  • 1
    What regex engine are you using? Commented Jul 26, 2013 at 16:50
  • If you need ANY ex# to be ignored, you need to state this in your question. We can resolve that! Commented Jul 26, 2013 at 16:56

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

7 Comments

You had correct syntax before I did. I deleted my answer. +1
Thanks for help. This is really work, but when I try it with .ex11 is matches too:( I guess it will be simply different extension.
.* should probably be \S+.
@arshajii: Yes, sure \S+ will be better.
Sorry it's work perfect. Thanks a lot! I was confusing a little bit :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.