Internet

Regular expression Useful for Google Analytics

March 20, 2012 by Sarath DR in Internet, Tips with 0 Comments

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 , ,

Share this to

Related Posts

Leave a reply

Your email address will not be published. Required fields are marked *

*

About
View Sarath D R's profile on LinkedIn

I am a technology consultant and an entrepreneur focused on the following technologies Java,Spring, Android, Angular, Asterisk, Symfony, Cake , Code-Igniter, Jquery , XAMPP, XHTML, AJAX, MySql, Seo, Web Design, Wordpress, iPhone development.

Today’s Tips
  • Generate Codova.jar file from Phonegap project using ant
  • Google map javascript client  to find the geographic co-ordinates  from  Address or post code
  • Update Android main UI from Webview – Phonegap Plugin
  • Jplayer is not working  with HTC One Android 4.3 version browser
  • Regular expression to validate mobile phone numbers starting with + ( plus ) – php
  • Simple pagination script for PHP
  • Useful adb ( Android Debug Bridge ) commands
  • Change the javascript files url to absolute url – Symfony 1.4
  • Set Http authentication header from Client – PHP / CURL

This site uses cookies from Google to deliver its services, to personalise ads and to analyse traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.This site also uses cookies from Google to deliver its services, to personalise ads and to analyse traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies.

Close