Regular Expressions can be entered in the page targeting field for all of Insightful's tools.


What are Regular Expressions?


A Regular Expression, REGEX or REGEXP for short, is a special text string for describing a search pattern.


Regex Tester: This regex tester can help you build regular expressions.


Notice: Make sure 'javascript' is selected in the menu on the left.




I. Wildcard examples (where * can be anything)



1. Your target pages:


www.example.com/pages/*

(records data from all the site starting with www.example.com/pages/)


Code to put into the URL field:

^(http|https):\/\/www.example.com\/pages\/.*$



2. Your target pages:


www.example.com/pages/*/article/

(records data from all the site starting with www.example.com/pages/ and ending with /article/))


Code to put into the URL field:

^(http|https):\/\/www.example.com\/pages\/[^\/]+\/article\/$



3. Your target pages:


www.example.com/user/<user_id>/profile/(numeric user_id)

(records data from all the user profile pages)


Code to put into the URL field:

^(http|https):\/\/www.example.com\/user\/[0-9]+\/profile\/$




II. Wildcard excluding a certain pattern


1. Your target pages:


All pages (URLs) which match a pattern and do not include the word "article" or "post" www.example.com/pages/*/subpage/


Code to put into the URL field:

^(http|https):\/\/www.example.com\/pages\/(?!article|post)[^\/]+\/subpage\/$



III. Excluding certain words or patterns in a URL


1. Your target pages:

All pages which do not include "/somepage" and "/someotherpage"


Code to put into the URL field:

^((?!\/somepage|\/someotherpage).)*$



2. Your target pages:


Pages which include the word "page" and do not include "somepage":


Code to put into the URL field:

(?=.*page.*)(?!.*otherpage).*


3. Multiple pages which don't follow any pattern


You want to target these three pages:

www.example.com/pages/article-one/details/

www.example.com/pages/some-random-word/details/

www.example.com/pages/another-post/details/


Code to put into the URL field:

^(http|https):\/\/www.example.com\/pages\/(article-one|some-random-word|another-post)\/details\/$