Skip to main content
Using RegEx for targeting your surveys

How to use Regular Expressions to display your surveys on specific pages

Agnieszka avatar
Written by Agnieszka
Updated over 10 months ago

Regular Expressions allow people to search for specific strings of characters and pieces of information in a line of code.

With RegEx, you can:

  • target your Website or in-product surveys to be shown on specific subpages of your website;

  • choose to show your survey on many web pages with a common part of the URL without applying a number of different rules;

  • collect relevant feedback by triggering a survey on a chosen group of pages;

  • filter your responses for better respondent sampling and analysis.

In this article, you'll learn what Regular Expressions you can use to target your survey and how to ensure you only collect visitors' responses on your chosen URLs.

πŸ“Œ This feature is available on some of the plans. If you are interested in testing the recurring website surveys feature, drop us a line at sales@survicate.com or talk to us on chat πŸ‘‰.

Step 1. Create a Website or in-product survey

Create a new Website or in-product survey. You can either set up a survey of your own (start from scratch), select a survey from our templates library (start from template), create a survey with AI, or import questions you prepared before:

Step 2. Target the survey using RegEx

1. Go to the Target > Triggers tab of your Website or in-product survey. In the section Where would you like to show the survey? click on Only certain pages.

Under Show the survey on the following pages search for and select URL RegEx.

2. You can now type the URL on which you'd like to show your survey.

Instead of adding several URLs, you can replace an interchangeable part of the URL with one of the RegEx characters. This feature will trigger the survey on all web pages whose URLs' remaining characters match your settings.

You can click on Add new pages to include several rules regarding where the survey should appear.

3. You can also exclude web pages on which you'd rather not show your survey.

Simply click on Don't show on certain pages and decide where the survey shouldn't appear. You can use RegEx here as well.

πŸ’‘ Here, you can find some of the most widely used RegEx characters and their explanations which may be helpful while targeting your website or in-product survey.

. The Dot is used when you want any character to match (ex .a RegEx will match all the bold letters from the following string (car, leaf, spear).

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

+ The Plus is similar to a star, but matches one or more characters (ex. a+r RegEx 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 can be used 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 below 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!

Step 3. Filter survey results

1. After collecting feedback, head over to your survey's Analyze tab to see the overall results, as well as to see which answers were provided on which URLs.

2. Click on Filter and select Response URL.

Here, you can type the whole URL that you want to analyze or just a part. You can analyze which web pages gather what kind of feedback and act on it to improve the experience for your website visitors.

Popular use-cases

Here you can find some examples of using RegEx that you can also implement in your survey's Target tab.

1. Targeting only 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 below code

.*(?=feature).*

will match these web pages:
​solutions.com/feature
solutions.com/industry/energy/feature?documentation.html


but will not match URLs such as:
​solutions.com/industry/pricing
​solutions.com/help/?q=account

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

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

.*(?!feature).*

will match these web pages:
​solutions.com/industry/pricing
solutions.com/help/?q=account


but will not match URLs such as:
​solutions.com/feature
solutions.com/industry/energy/feature?documentation.html

πŸš€ For more inspiration, feel free to visit these websites:
​https://regexone.com/
​https://regexr.com/

Troubleshooting

I don't see the survey even though I am on the correct URL

If you don't see the survey, please check if you have the Survicate tracking code installed on your website.

It's also possible you have already answered the survey. Please try changing its Frequency settings.

πŸ“ž If you have any questions about targeting a survey using Regular Expressions, please reach out to us at support@survicate.com or strike up a chat conversationΒ πŸ‘‰

Did this answer your question?