I have the below regex, but how can I remove the querystring entirely if it is present:
^~/(.*)/restaurant/(.*)
eg. the url
/seattle/restaurant/sushi?page=2
or
/seattle/restaurant/sushi?somethingelse=something
or
/seatthe/restaurant/sushi
should just return seattle and restaurant and sushi and remove any querystring if it is present.
(sorry for reposting a similar question, but I couldn't get the answer to work in my previous question).
thanks
Thomas
This regex:
(/[^?]+).*
Should match the initial section of your URL and put it in a group.
So it will match /seattle/restaurant/sushi and put the value in a group.
You can use something like this: (/.*?/restaurant[^?]+).* if you want to handle just URLs with the word restaurant as the second word between the slashes.
Edit: Something like so should yield 3 groups: /(.*?)/(restaurant)/([^?]+).*. Group 1 being seatthe, group 2 being restaurant and group 3 being sushi. If after the last / there is a ?, the regex discards the ? and everything which follows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With