Jump to content

Recommended Posts

For google analytics, I need to have a regex that will match our goal pages.

 

The part of the url that it would be looking at would be similar to:

/variable/checkout/variable/thank-you

 

These urls will have exactly 4 segments. "variable" segments can contain only letters (case insensitive), numbers, dashes and are required.

I need to specifically match "checkout" in the 2nd segment and "thank-you" in the 4th.  There is no trailing / after thank-you.

 

Any help would be greatly appreciated.  Regex is my weakness.  (I know...I know..)

 

Well, the individual letters in each segment would be [a-z0-9-] (add a A-Z if the regex isn't already case-insensitive), and to have more than one use a + quantifier. The rest is basically just a literal copy of the URL you're matching.

\/+[a-z0-9-]+\/checkout\/+[a-z0-9-]+\/thank-you
 

 

This seems to work, at least when testing with preg_match(), does it look correct with the rules I stated?  I basically escaped all slashes and chained everything together with a + that wasn't static.  I think (lol)

A little too overzealous with the pluses.

/[a-z0-9-]+/checkout/[a-z0-9-]+/thank-you
You might not need to escape the slashes (they'd probably tell you to if you did) and you might need ^ and $ anchors (if they say anything about it matching parts of the URL and not the entire thing).
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.