Reena Verma
Reena Verma

Reputation: 1685

Use regex to find 2 params in URL

I'm setting up an AB test and I don't want certain pages, to be included in my AB test based on the query params in the URL.

I want to use regex to find two params in this URL:

I have the following regex to find &rooms[0][adults]=2:

(rooms)\W0\W\Wadults\W=[2-9]

But I'm not sure how to expand this, to also look for and match &offerRooms[0][adults]=2

Essentially, I want my regex to find both of this params in one regex lookup.

Any pointers would be helpful!

Thanks,

Upvotes: 0

Views: 188

Answers (1)

Kristof Neirynck
Kristof Neirynck

Reputation: 4162

I'm not entirely sure of what it is you want to do. This regex will find rooms[0][adults]=2 and offerRooms[0][adults]=2. Is that what you're looking for?

(rooms|offerRooms)\[0\]\[adults\]=[2-9]

If you only want the urls that contain both and rooms always comes before offerRooms it is straight forward.

rooms\[0\]\[adults\]=[2-9].*offerRooms\[0\]\[adults\]=[2-9]

If you only want the urls that contain both and rooms doesn't always come before offerRooms it is rather complicated and requires a lookahead. Here I look for rooms if followed by offerRooms OR offerRooms if followed by rooms.

(rooms\[0\]\[adults\]=[2-9](?=.*offerRooms\[0\]\[adults\]=[2-9])|offerRooms\[0\]\[adults\]=[2-9](?=.*rooms\[0\]\[adults\]=[2-9]))

Upvotes: 2

Related Questions