-1

I am trying to match regex for my URL structures below:

SPECIFIC CASE #1:
http://www.example.com/webapp/some-text.html
http://www.example.com/webapp/some-text-a1.html
http://www.example.com/webapp/some-a2-text.html

SPECIFIC CASE #2:
http://www.example.com/webapp/first-text-vs-some-text.html
http://www.example.com/webapp/first-text-a1-vs-sec-b2-text.html
http://www.example.com/webapp/first-text-a1-vs-sec-b2-text-vs-third-c3-text.html
http://www.example.com/webapp/some-text-a1-vs-sec-text-b2-vs-third-text-vs-last-text-c1.html

SPECIFIC CASE #3:
http://www.example.com/webapp/sub-app/some-text-a1.html 

My regex is:

SPECIFIC CASE #1:
\/webapp\/(.*)\.html

SPECIFIC CASE #3:
\/webapp\/sub-app\/(.*)\.html

Case #1 and #3 working. But for #2 it maches all including #1.

The thing is that my Web application is structured so If I visit the above example links some work and other gives me error 404.

I think my regex is wrong because I have multiple cases for that. Currently it is only working for specific case #1.

My guess is that my regex from above is not good for that. Do I need multuple regexes for that? Which one?

Is there a way for regex to check if value "vs" exists (one or multiple times) inside the given URL?

Any ideas or better solutions exist?

Any help would be appreciated!

Thanks a lot!

5
  • 1
    May I know what differs Case #2 from Case #1? Is it the vs keyword? Commented Apr 6, 2016 at 0:41
  • Exactly. The difference is the word "vs". Currently I am trying to match "vs" inside url with this regex (?:^|\W)vs(?:$|\W) or any other? Commented Apr 6, 2016 at 0:43
  • \/webapp\/.*(?:^|\W)vs(?:$|\W)+.*html - is this regex ok? Commented Apr 6, 2016 at 0:47
  • Which regex should I use so that I could capture URl which has not got vs word inside? Commented Apr 6, 2016 at 0:58
  • Almost got it. ^((?!vs).*)+.html but i need /webapp/ before. Commented Apr 6, 2016 at 1:02

1 Answer 1

1

How about this regex:

/\/webapp\/(.*)(-vs-.*)+\.html/

This regex matches any repetitive -vs-.* once or more.

Sample: https://3v4l.org/2gWlN

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

11 Comments

Thanks for solution that. It works! Brilliant! Also, regex .*^((?!vs).*)+.html is missing /webapp/ before for URls non-containing word "vs". Any ideas?
I don't quite understand.. :D
Sorry for bad english. Your regex works for vs (repetitive) - that is excellent. I am wondering how can i target CASE #1 or URLs that does not have these "vs" in? I have ^((?!vs).*)+.html but I am not sure if it is right because it is missing /webapp/ before.
So which means, you need single regex to match these three different set of URLs?
Yes, You are right. Is that possible to make a single one? I was thinking it should be simplified solution with few of them but, or I was wrong about it?
|

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.