0

I want to match repeat character(/) only once in the middle of the string. At the start it must be http://www.website/shop. Now I am using this code and it matches all html. How can I restrict it.

'^[http://www.website/shop/].*.html$'

With this regex, no result ^[http://]\W*(/){2}\W

Valid

   http://www.website/shop/men.html
   http://www.website/shop/women.html

Invalid

   http://www.website/shop/men/footwear.html
   http://www.website/shop/men/causal.html
   http://www.website/shop/women/footwear.html
2
  • Not clear what you're asking? I can't see how you expect valid and invalid to be any different... Commented Mar 28, 2013 at 1:06
  • 1
    \W is opposite of \w, i.e. it's any character except letters and numbers... Commented Mar 28, 2013 at 1:18

1 Answer 1

1

This regex should work

"http://www.website/shop/\w*.html"

... it won't match if there's another slash after the slashes in .../shop/

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

6 Comments

it is working but how about the link like "website/shop/men+hair.html". If I use your answer, I cannot get this kind of link.
this doesn't generate any html. The restrictions must start with "website/shop" and regex must not match the string if it has another slash. And the string can also have + in the middle of the html. Any ideas?
give me an example of when it fails so i can make sure i understand what you're saying
These are not matched with website/shop\w*\+*\w*.html. The program is just terminated.
|

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.