Using Regex

Introduction

Regular Expressions (Regex) is a powerful tool that helps you create sophisticated filters without complex AND/OR blocks. While it might look intimidating at first, this guide will break it down into simple, practical concepts that marketers can use daily.

Basic Syntax

The Building Blocks

💡 Important: Regex in HockeyStack is case sensitive

Common Use Cases

1. Contains One of Multiple Values

Instead of using multiple "contains" filters, use the OR operator:

/Renewal|Upsell|Cross-Sell/

This matches any text containing "Renewal", "Upsell", or "Cross-Sell"

2. Checking for Empty Values

To check if a field is empty:

/^$/

To check if a field is not empty:

/./

3. Brand Campaign Example

Let's say you want to match brand campaigns with these patterns:

  • "brand" in the middle

  • "brand_" at the start

  • "_brand" at the end

But NOT match "nonbrand_"

/_brand_|^brand_|_brand$/

Breaking it down:

  • _brand_ matches brand with underscores on both sides

  • ^brand_ matches brand with underscore at the start

  • _brand$ matches brand with underscore at the end

  • The | combines these patterns with OR logic

4. Special Character Matching

If you need to match special characters like "|" in your text:

/\|/

This tells regex to treat the "|" as regular text, not as an OR operator.

Testing Your Regex

  1. Paste your pattern (without the / delimiters)

  2. Test it against your sample text

  3. The website will explain each part of your pattern

Best Practices

  1. Start Simple: Begin with basic patterns and build up complexity

  2. Test Thoroughly: Always test your regex with various examples

  3. Document: Keep notes about what each regex pattern does

  4. Break It Down: Split complex patterns into smaller, understandable pieces

  5. Consider Case: Remember that HockeyStack regex is case sensitive

Need Help?

If you're unsure about a pattern:

  1. Break down what you're trying to match

  2. Test it on regex101.com

  3. Start with simple patterns

  4. Add complexity one piece at a time

Remember: Regex is a powerful tool that becomes easier with practice. Start with simple patterns and gradually build up to more complex ones as you become comfortable with the basics.

Last updated