---
title: "Using RegEx matching in Segmentation"
description: "Regex matching lets you filter profiles based on text patterns instead of exact values. This is useful for finding profiles that follow a specific format, like email addresses from certain domains or phone numbers in a particular format."
canonical_url: "https://help.klaviyo.com/hc/en-us/articles/45673762457243"
markdown_url: "https://help.klaviyo.com/hc/en-us/articles/45673762457243.md"
locale: "en-us"
category: "Audience"
section: "Build and use segments"
updated: "2026-11-03"
---

# Using RegEx matching in Segmentation

## **What is regex matching?**

Regex matching lets you filter profiles based on text patterns instead of exact values. This is useful for finding profiles that follow a specific format, like email addresses from certain domains or phone numbers in a particular format.

**⚠️ Important:** Regex always matches the complete value from beginning to end.

## **How to use regex**

When building a segment, you can use 2 regex operators with **Text** properties:

- **matches regex** - Includes profiles where the value matches your regex

- **does not match regex** - Includes profiles where the value does not match your regex



Use regex in the following segment conditions:

- **Properties about someone** (including custom objects). To use object data, first create a custom object. Learn [how to use custom objects in segments](https://help.klaviyo.com/hc/en-us/articles/35146339009691.md).



![Image](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/aa4f04ce209a39879488232597aa3b4bebb998b8-2254x794.png?auto=format)

![Image](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/0fbfcb17d2f0e5f3140e2da6c79358c95746a87a-2426x680.png?auto=format)

- Filters on **What someone has done (or not done)** and **Steps someone has taken (or not taken) in a specific order**



Event funnels are included in Personalization and Advanced KDP. Learn [how to use event funnels in segmentation](https://help.klaviyo.com/hc/en-us/articles/42691974773147.md).

![Image](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/142437d6aaabd29e1532ddb37d02c40f506a14ce-2266x924.png?auto=format)

### Apply a regex filter

1. [Open the segment builder for a new segment](https://help.klaviyo.com/hc/en-us/articles/115005237908.md), or open an existing segment and click **Edit definition**.

2. Choose one of the conditions above and select the property to match. For an event condition, select an event and click its filter icon to choose the event property.

3. Use a **Text** property. If the data type is editable, select **Text**.

4. Select **matches regex** or **does not match regex** and enter your pattern.

5. Click **Create segment** for a new segment or **Update segment** to save changes to an existing segment.



## **Regex basics**

#### **Matching characters**

- Letters and numbers - Type normally: hello matches "hello"

- Any digit - Use \d to match any number 0-9

- Any letter - Use [a-z] for lowercase, [A-Z] for uppercase, or [a-zA-Z] for both

- Either/or - Use | to match options: gmail|yahoo matches either "gmail" or "yahoo"

- Anything - Use .* to match any characters



#### **Special characters**

Add a backslash \ before these to match them literally:

- Period: \. matches a period

- Plus sign: \+ matches a plus sign

- Parentheses: \( and \) match parentheses



#### **Repeating patterns**

- {5} - Exactly 5 times (e.g., \d{5} matches 5 digits)

- {2,4} - Between 2 and 4 times

- ? - Optional (0 or 1 time)



Note: Repetition bounds in {n}, {n,m}, or {n,} cannot exceed 1,000. This does not limit * or + to 1,000 repetitions.

## **Common examples**

#### **Email addresses**

- Specific domain:

  - .*@example\.com

  - Matches: john@example.com, support@example.com

- Multiple domains:

  - .*@(gmail|yahoo|hotmail)\.com

  - Matches: user@gmail.com, user@yahoo.com, [user@hotmail.com](mailto:user@hotmail.com)

- Any .com email:

  - .*@.*\.com



#### **Phone numbers**

- 10-digit US number

  - \d{10}

  - Matches: 5551234567

- Formatted with parentheses:

  - \(\d{3}\) \d{3}-\d{4}

  - Matches: (555) 123-4567



#### **Postal codes**

- 5-digit ZIP:

  - \d{5}

  - Matches: 12345

- ZIP+4:

  - \d{5}-\d{4}

  - Matches: 12345-6789



**For advanced references: our implementation uses Google RE2 as our standard.** [**Learn more here**](https://github.com/google/re2/wiki/Syntax)**.**

## **Regex limits**

| **Limit** | **Value** | **Example** |
| --- | --- | --- |
| Regex length | max 1,000 characters | - |
| Regex lines | max 100 lines | - |
| Counted repetition bounds | Maximum bound: 1,000 | \d{1000} allowed \d{1001} not allowed |
| Top-level \| separators | Maximum 5 separators (6 alternatives) | a\|b\|c\|d\|e\|f is allowed; a\|b\|c\|d\|e\|f\|g exceeds the limit |

**Additionally, the following features are not supported at this time.**

| **Feature** | **Example** |
| --- | --- |
| Lookahead/Lookbehind | (?=...), (?!...), (?<=...), (?<!...) |
| Backreferences | \1, \2, (\w+)\s+\1 |
| Unicode escapes | \uXXXX, \u00A0 |
| Nested quantifiers | (a+)+, (x*)*, (a{2,5})+ |

## **Tips for success**

**1. Regex matches the complete value**

Your regex must describe the entire value, not just part of it.

Wrong: gmail\.com (only matches the text "gmail.com")

Right: .*@gmail\.com (matches complete emails like john@gmail.com)

**2. Escape literal periods**

When matching .com, .net, etc., write it as \.com with a backslash.

Wrong: .*@gmail.com (the unescaped period matches any character)

Right: .*@gmail\.com (matches the literal period in emails like john@gmail.com)

**3. Use .* for "Anything"**

Match any characters with .*

- .*@company\.com - Any email at [company.com](http://company.com)

- \+.* - Anything starting with +

- .*urgent.* - Text containing "urgent"



**4. Start simple, then refine**

Begin with a basic regex and add details gradually.

- Example: .*@gmail\.com → [a-z]+\.[a-z]+@gmail\.com



Split complex logic into multiple simple conditions when possible. Join the conditions with **AND** when profiles must meet both, as in the example below.

- Example for "Gmail or Yahoo emails from California":

  - Filter 1: Email matches regex .*@(gmail|yahoo)\.com

  - Filter 2: State equals California



**5. RegEx is case sensitive by default**

If you want to make a statement case insensitive, you can add `(?i)` as a prefix.

- Product matches (?i)^iphone$



## **When to use regex vs. standard operators**

Use regex when you need to match specific formats or patterns. For simpler needs, we strongly recommend using standard operators instead:

- Contains - Text appears anywhere

- Starts with - Matches the beginning

- Ends with - Matches the ending

- Equals - Exact match
