How to Use Regular Expressions to Target a Basic Query String in URLs


Use regular expressions (regex) to target URLs containing query strings. A query string is part of a URL that follows a question mark and contains parameters. This article explains how to effectively employ regex to target different types of query strings, such as those used for tracking advertising campaigns or promo codes within your website.


In this article, you will learn to use regex to target the following query strings in a URL:


1. Facebook Links

2. Email Promo Code


  Targeting Facebook Links Using Basic Query String


To target URLs with query strings like Facebook tracking IDs, you can use regular expressions. Here's how:

  1. Components to Target:

    • Protocol and Subdomain: www
    • Domain:
    • Path and Parameters: ./.?bffb
  2. Explanation: In a URL like: The tracking ID "bffb" is separated from the rest of the URL by a single question mark. To match any Buzzfeed story page visited via a Facebook link, the regex "./.?bffb" is used. Ensure that slashes within sections are escaped using backslashes.

  3. Examples:


Now, the survey will be displayed on any page in the format: The slashes between sections must be escaped, and to make it easy, Qualaroo allows anything to be in those slashes by using the .*

(dot -star) character combination.


  Targeting Email Promo Code Using Basic Query String


Regex can also target URLs containing promo codes, making it easy to integrate surveys. Here's how:

  1. Components to Target:

    • Protocol and Subdomain: www
    • Domain:
    • Path and Parameters: products/new_items?promo=shipping.*
  2. Explanation: Businesses often use promo codes for discounts at checkout. By applying regex, you can target customers who click on email links and land on your website. For instance, the regex "products/new_items?promo=shipping.*" targets URLs where the parameter "promo" starts with "shipping" and is followed by anything else.

  3. Example:


With this regex, any user landing on the URL below with a promo code matching the pattern (“shipping” followed by anything else, like a customer ID) will see the survey.



That is all about using a basic query string in a regular expression. If you encounter any issues or have any questions, feel free to contact our support team.



© 2005 - 2024 ProProfs