0

As a disclaimer, I must say that my experience with regular expressions is very limited. I am using Optimizely for A/B testing and have run into a problem. I only want my experiment to run on one page, however, this page's URL-structure is somewhat complicated. The URL-structure of the page where I want to run my experiment looks like this:

https://mywebsite.co/term/public_id/edit/pricing

The problem is the public_id that changes dynamically, whenever a new user goes through the signup flow. How can I use regex to target this page exclusively? I have been trying to figure it out these past days but without any luck. Optimizely regex docs can be found here. I can't just use a simple match because /term/ appears in the URL of several pages on my site.

DBE7
  • 766
  • 2
  • 9
  • 23
  • 1
    Tried `mywebsite\.co/somepage/.*?/edit/pricing`? – trincot Jun 25 '16 at 17:53
  • A few questions to understand your question : 1.So basically the url format you will have for your test will be something like: "https://mywebsite.co/somepage/" + public_id + "/edit/pricing" ? What is public_id ? text or only numbers or smth else ? 2. I'm not familiar with optimizely. What do you mean by redirect ? How do you usually redirect ? – shrimpdrake Jun 25 '16 at 17:58
  • A sample `public_id` could be `bqvnd`. I never mentioned redirect. – DBE7 Jun 25 '16 at 18:01
  • 1
    Perfect. @trincot solved my problem. Thanks. – DBE7 Jun 25 '16 at 18:02
  • Ok, I posted it as answer. – trincot Jun 25 '16 at 18:22

1 Answers1

2

You could use this regular expression:

 mywebsite\.co/somepage/.*?/edit/pricing

The .* part means any character can occur here any number of times. The additional ? makes it lazy, meaning the rest of the regular expression will kick in as soon as possible.

Note that a literal . needs to be escaped with a backslash, like \.

trincot
  • 317,000
  • 35
  • 244
  • 286