Cannot get my multiple regex working for specific

2019-09-19 10:07发布

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!

1条回答
乱世女痞
2楼-- · 2019-09-19 11:06

How about this regex:

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

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

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

查看更多
登录 后发表回答