Regular Expressions allow people to search for certain 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.

Table of contents:

  1. Create a Website or in-product survey

  2. Target the survey using RegEx

  3. Filter survey results

  4. Popular use cases

  5. Troubleshooting

  6. Best practices

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) or select a survey from our templates library (start from template).

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 choose to 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 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.

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.

Best practices

Set up your survey Audience

Show the survey only to users from a chosen visit source, to visitors speaking a particular language, or using a mobile or desktop device. Learn how to achieve this here.

Show your survey with a delay or when a visitor is about to leave the page

Choose to show your survey after someone has scrolled a part of your webpage or when they're about to exit. Visit our targeting basic guide to learn how to achieve this.

📞 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?