CroNiX Posted March 26, 2013 Share Posted March 26, 2013 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..) Link to comment https://forums.phpfreaks.com/topic/276156-google-analytics-match-specific-parts-of-url/ Share on other sites More sharing options...
requinix Posted March 26, 2013 Share Posted March 26, 2013 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. Link to comment https://forums.phpfreaks.com/topic/276156-google-analytics-match-specific-parts-of-url/#findComment-1421048 Share on other sites More sharing options...
CroNiX Posted March 26, 2013 Author Share Posted March 26, 2013 \/+[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) Link to comment https://forums.phpfreaks.com/topic/276156-google-analytics-match-specific-parts-of-url/#findComment-1421051 Share on other sites More sharing options...
requinix Posted March 26, 2013 Share Posted March 26, 2013 A little too overzealous with the pluses. /[a-z0-9-]+/checkout/[a-z0-9-]+/thank-youYou 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). Link to comment https://forums.phpfreaks.com/topic/276156-google-analytics-match-specific-parts-of-url/#findComment-1421053 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.