How to Use OptinMonster’s Matching The Pattern RegEx Rules

OptinMonster makes it easy to target campaigns to URLs matching a pattern or RegEx using our Display Rules.

In this article, you’ll learn how to show or hide your campaigns using pattern matching or RegEx on your site.

Before You Start

Here are some things to know before you begin:

  • “Matches the pattern” is an option available with some Display Rules in the campaign builder to provide you with more advanced functionality for hiding and showing campaigns on your site.
  • This feature allows you to use RegEx (Regular Expression). RegEx looks for characters: be it letters, numbers, or specific symbols to identify a pattern.
  • Because RegEx engines evaluate “patterns of characters”, OptinMonster has employed the phrase, “matches the pattern” because it is a more easily recognizable phrase to describe what is occurring.

Using “Matches the Pattern”

You can use “matches the pattern” with the following Display Rules when editing your campaigns:

To use RegEx in your campaign’s Display Rules, follow these steps:

  1. In the campaign builder navigate to the Display Rules view.
    Display Rules OM editor
  2. Next, select the top Edit button in the Summary view to modify the rules.
  3. Edit or add a new rule. Choose one of the options outlined in the previous list above. In this example, we’ll choose “the current URL path” rule.
    Change Display Rules to Current URL Path-min
  4. You can now choose the operator from the dropdown list, locate and select matches the pattern.
    Matches the pattern operator in the OptinMonster Display Rules allows you to use RegEx.
  5. You’ll be provided a field to enter your RegEx pattern into.
  6. When you’re finished, click Save.

Example

The following are some examples of RegEx pattern matching you could use with your campaigns.

Exclude campaign from Showing on Multiple Language Directories

Let’s say your default language is English for your site, so that site shows on mysite.com while your other sites load on URL paths like: mysite.com/es/ or mysite.com/de/ or similar language structures, etc.

In this case, you do not want your campaign to load on those other languages. Therefore, you could enter in a slightly more complex RegEx pattern to prevent the campaign from loading on pages that start with those certain language pre-fixes:

In the situation where you have the following languages: es, de, ja, and ru, you could use the current URL path rule and set the following RegEx Pattern (“Matching the Pattern”):

^(?!(es|de|ja|ru)b/?).+

The above will prevent a campaign from showing on pages where the url path (the part after the .com) begins with:

  • es/
  • de/
  • ja/
  • ru/

Essentially, the campaign would only show here: mysite.com and related English pages, but never the pages of those other languages.

Troubleshooting

Is there a simpler way to target my campaigns?

Some pre-made RegEx Rules are already natively built into OptinMonster’s Display Rules. You can try to use those pre-made rules such as “Contains”, “Does Not Contain”, “Starts With”, “Ends With”, etc., before attempting to use this advanced approach.

Do you have any resources to help me with using and testing RegEx pattern matching?

We have found the following sites helpful for using and testing out RegEx.

When creating your pattern to use in OptinMonster, we strongly suggest using the sites listed above to test the pattern before adding it to your campaign. This will help speed up testing for your campaign.