Regular Expressions allow people to search for certain strings of characters and pieces of information in a line of code. With Survicate you can use them to target specific sets of pages without applying a number of different rules. 

Most widely used characters

. The Dot is used when you want any character to match. For example, if you have .a regex it will match all the bold letters from the following string (car, leaf, spear).

* The Star symbol matches zero or more of preceding character (ex. a*r regex matches the following: car aaaaar lure).

+ The Plus is similar to a star, but matches one or more character. It means that in the following string regex a+r will match: car aaaaar lure.

.* Dot-star matches any string of characters. For instance, if you want to target all visitors that have used your coupon, you can write a piece of Regex

coupon=.*

and regardless of coupon number (ex. coupon=132, coupon=9074217, coupon=4238) it will match.
\ The Backslash lets you escape the special characters. For example, if you need to escape the dots function: solutions\.com means solutions -dot- com, not solutions -any character- com. You will also need to escape slashes (/) so that solutions.com/industry/security in RegEx will like this: 

solutions\.com\/industry\/security

? The Question mark is for marking preceding characters as optional, for example if you want to match subdomain.solutions.com as well as solutions.com you should write your RegEx like this:

(subdomain\.)?solutions\.com

So the subdomain. will be optional.
(   ) The Brackets are for grouping specific items together, as shown in the previous example where the whole string in brackets  (subdomain\.) placed before the ? was optional.
| The Vertical Bar (or Pipe symbol) allows you to match more than one element, for instance, the RegEx

solutions\.com\/industry\/(security|it)

Will match either solutions.com/industry/security or solutions.com/industry/it. ❗️Remember to put the elements you want to match in brackets!

Popular use-cases

Targeting only those pages that have a specific string in their URL

If you want to target every page that contains a specific word, use (?=stringyouwantinURL) around the word, for instance, the word feature in the code

.*(?=feature).*

Will match
solutions.com/feature
solutions.com/industry/energy/feature?documentation.html
but won't match URLs like:
solutions.com/industry/pricing
solutions.com/help/?q=account

Excluding the pages that don't have a specific string in their URL

If you want to exclude every page that contains a specific word, use (?!stringyoudontwantinURL) around the word, for instance the word feature in the code

.*(?!feature).*

Will match
solutions.com/industry/pricing
solutions.com/help/?q=account
but won't match:
solutions.com/feature
solutions.com/industry/energy/feature?documentation.html

For more info please visit these pages:
https://regexone.com/
https://regexr.com/

Did this answer your question?