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:
- Navigate to the Display Rules view in the campaign builder.
- When adding a Display Rule that supports pattern matching, select matches the pattern from the operator dropdown and your RegEx into the text field.
- When you’re finished, Save the campaign.
The following are some examples of RegEx pattern matching you could use with your campaigns.
Exclude the 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/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”):
The above will prevent a campaign from showing on pages where the url path (the part after the
.com) begins with:
Essentially, the campaign would only show here:
mysite.com and related English pages, but never the pages of those other languages.
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.