Variance offers expert Guide Editors the ability to use Regex for Guide and Card Triggers. Regex, short for “regular expression”, is a tool for checking if text meets certain criteria. You can use Regex with Variance to detect if a user is on a certain page and show them a Guide or Trigger a card transition as necessary. If you're not familiar with Regex, don't sweat it, there are lots of other ways to build guides.
First things first, we support Perl Compatible Regular Expressions (PCRE). If you need a refresher, here's a good cheatsheet.
Writing Good Regex
Within Guides we are using Regex for matching URLs. This is because often you want a Guide or Card Trigger to activate on any URL of a particular type, not just the specific one you are on at that moment. To that end, we recommend being careful that you are either including or excluding the unique ID for the page you're on in the Regex. Let's use our current URL as an example: http://help.variance.com/en/articles/3991299-regex
If we wanted to trigger a guide on this specific page, our best bet would be to write some Regex using what we can assume is the unique ID. That would look something like this:
On the other hand, if we wanted it to fire on all articles we could use this Regex:
\/articles\/\d+ (we are assuming there is always a numbered ID after
/articles/). (As a side note, many sites have Areas configured, which work similarly).
Tips & Tricks
One thing we recommend is using Regex101.com to check you got it right. The color coding and live-editing makes it easy to figure out. Here's what it looks like for the Regex above:
Another great resource for writing working Regex (especially if you're having some trouble) is regexper.com. They offer a visualizer to help you see exactly how your code is working. Here's what they show us for the Regex above:
You can see that it first matches
/articles/ exactly and then it loops through as many digits as it can find.