Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
141 views
in Technique[技术] by (71.8m points)

php - Cannot get my multiple regex working for specific case in URL structure

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

How about this regex:

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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...