Sometimes in google analytics you need to set some goal with a particular string in the url or you need to avoid some string to from the url. You can set the goals with url regular expression matching with these regular expressions.
1. If you want to some string mandatory in the url use the below regular expression
preg_match("/^(?=.*?\bmatching\b).*$/", "http://tech.sarathdr.com/matching", $matches ); echo $match[0]; // Outputs http://tech.sarathdr.com/matching |
2. Regular expression to find urls without the matching string.
<?php preg_match("/^((?!matching).)*$/", "http://tech.sarathdr.com/matching", $matches ); echo $matches[0]; // Outputs nothing ?> |
3. If you need both things together in a single regular expression use the below one
preg_match("/^(?=.*?\bmatching\b)((?!avoid_this).)*$/", "http://tech.sarathdr.com/matching/avoid_this", $matches ); echo $matches[0]; // Outputs nothing preg_match("/^(?=.*?\bmatching\b)((?!avoid_this).)*$/", "http://tech.sarathdr.com/matching/", $matches ); echo $matches[0]; // Outputs http://tech.sarathdr.com/matching/ |
Tagged google analytics regular expression, parse url, regular expression