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/sushiand put the value in a group.You can use something like this:
(/.*?/restaurant[^?]+).*if you want to handle just URLs with the wordrestaurantas the second word between the slashes.Edit: Something like so should yield 3 groups:
/(.*?)/(restaurant)/([^?]+).*. Group 1 beingseatthe, group 2 beingrestaurantand group 3 beingsushi. If after the last/there is a?, the regex discards the?and everything which follows.