Reputation: 13
I'm looking to capture the string between www.my-website.com/buy/
and -PERMANENT.html
if it exists, but am having trouble doing so. I'm unsure how to create a capture group that would ignore a consecutive string. My attempts have failed so far.
www\.my-website\.com\/buy\/([^-PERMANENT.html]*)
www.my-website.com/buy/fork (Capture fork)
www.my-website.com/buy/wand (Capture wand)
www.my-website.com/buy/ball-PERMANENT.html (Capture ball)
www.my-website.com/buy/bike-PERMANENT.html (Capture bike)
www.my-website.com/buy/base-PERMANENT.html-ball (Capture base)
www.my-website.com/buy/wall-PERMANENT.html-glue (Capture wall)
Upvotes: 1
Views: 66
Reputation: 425033
You don't even need groups. The whole match of this regex is your target:
(?<=www\.my-website\.com\/buy\/).*?(?=-PERMANENT.html|$)
See live demo.
Upvotes: 1
Reputation: 8413
If your URLs are really that simple, you could go by lazy matching, like
www\.my-website\.com\/buy\/(.*?)(?:-PERMANENT.html|$)
See the demo
Upvotes: 1