# 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:

```regex
/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:

```regex
/^$/
```

To check if a field is not empty:

```regex
/./
```

#### 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\_"

```regex
/_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:

```regex
/\|/
```

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

### Testing Your Regex

1. Visit [regex101.com](https://regex101.com)
2. Paste your pattern (without the `/` delimiters)
3. Test it against your sample text
4. 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.
