Skip to main content

Regex Segmentation

Use regular expressions in the Segment Builder for advanced text pattern matching — for power users only.

About Regex Segmentation

The Segment Builder supports a Regex match type for text-based conditions. This is the right tool when a single Equals, Contains, Starts with, or Ends with can't express what you need — for example, matching multiple variations of a domain, validating a format, or capturing one of several values in a single condition.


In this article you'll find what regex is and where it's available in the Segment Builder, the supported syntax, worked examples for common use cases, and a troubleshooting table for the most common regex mistakes.

In this article


🚨 For advanced users only: Regex is unforgiving — a typo in the pattern can silently produce a Segment that matches nothing, or matches too much. Always Calculate and Show Profiles before using a regex Segment in a live send. If you're not familiar with regex syntax, use the standard Contains / Starts with / Ends with operators instead.


About regex in the Segment Builder

A regular expression — or regex — is a sequence of characters that defines a search pattern. Where Contains "gmail" matches only the literal string "gmail", a regex like gmail|hotmail|outlook can match any of three values in a single condition.

The Segment Builder supports a subset of regex features. The full list of supported syntax is in the Supported syntax section below.


Where you can use regex

Regex is available as a match type on:

  • Text Attributes — for example, First name, Email, City, or any custom text Attribute

  • Text-based Event data — for example, the address field within a Sign-up bar Submit event, or the URL string in a Page view event

To use regex on a condition, open the cogwheel and select Regex as the match type from the operator dropdown.


Supported syntax

When working with regular expressions in the Segment Builder, it is important that you consider the following limitations in order to successfully use the Regex Match Type. These are the specifications as to what the Segment Builder allows:

  • 1 and 2 bit unicode characters.

  • [abc] , [^abc] - ranges.

  • [a-q] , [A-Q] , [0-7] , [^a-q] , [^A-Q] , [^0-7] - "between" ranges.

  • (a|b) - alternatives.

  • . - any character except new line.

  • * , + , {n,m} , {n,} , {n} - quantifiers.

  • ^ , $ - beginning and end of the string.

Syntax

Meaning

Example

1 and 2 byte unicode characters

Standard ASCII and most extended characters

Letters, digits, common symbols

[abc]

Match any single character in the set

[aeiou] matches any vowel

[^abc]

Match any single character not in the set

[^0-9] matches anything that isn't a digit

[a-q], [A-Q], [0-7]

Match a character in the range

[A-Z] matches any uppercase letter

[^a-q], [^A-Q], [^0-7]

Match a character outside the range

[^a-z] matches anything that isn't a lowercase letter

(a|b)

Match alternatives — either pattern works

(gmail|hotmail|outlook) matches any of the three

.

Match any single character except a newline

a.c matches abc, a1c, a-c

*

Match the preceding character zero or more times

ab* matches a, ab, abb, abbb

+

Match the preceding character one or more times

ab+ matches ab, abb… but not a

{n}, {n,}, {n,m}

Match exactly n, at least n, or between n and m times

[0-9]{4} matches any 4-digit number

^

Anchor to the start of the string

^Hello matches strings that start with "Hello"

$

Anchor to the end of the string

\.com$ matches strings ending in ".com"

⚠️ Note: Lookaheads, lookbehinds, named groups, backreferences, and other advanced regex features are not supported. If your pattern needs them, build the logic with multiple standard conditions joined by AND/OR instead.


Common use cases

Match multiple email domains in one condition

Goal: capture Profiles whose email is on Gmail, Hotmail, or Outlook.

  • Condition: Email attribute

  • Operator: Regex

  • Pattern: @(gmail|hotmail|outlook)\.

Without regex this would be three separate conditions joined by OR. With regex it's one.

Match a postcode format

Goal: capture Profiles whose postcode follows the UK format (e.g. SW1A 1AA).

  • Condition: Postcode attribute

  • Operator: Regex

  • Pattern: ^[A-Z]{1,2}[0-9][A-Z0-9]? [0-9][A-Z]{2}$

Match URLs that include a year

Goal: capture page views on any blog post URL that ends with a 4-digit year (e.g. /blog/article-2026).

  • Condition: Page view event, URL string data

  • Operator: Regex

  • Pattern: /blog/.*-[0-9]{4}$

Match Profiles whose first name starts with a specific letter range

Goal: A/B test segmentation — capture Profiles whose first name starts with A through M.

  • Condition: First name attribute

  • Operator: Regex

  • Pattern: ^[A-Ma-m]

💡 Tip: Test your regex on a regex sandbox like regex101.com before pasting it into the Segment Builder. Paste a few real values from your audience and confirm the pattern matches what you expect.


Troubleshooting

Issue

Likely cause

Fix

Segment returns 0 Profiles but the data is clearly there

Case sensitivity — regex is case sensitive by default

Add both cases to your character set, e.g. [Gg]mail, or use the alternatives syntax (gmail|Gmail|GMAIL)

Pattern matches far more Profiles than expected

Missing anchors — without ^ or $, the pattern matches anywhere in the string

Anchor the pattern. ^abc$ matches only "abc"; abc matches anything containing "abc"

Special character isn't matching as a literal

Characters like ., *, +, (, ), [, ], {, }, |, ^, $, ?, \ have special meaning

Escape with a backslash, e.g. \.com matches the literal ".com"

Lookahead, lookbehind, or backreference doesn't work

Not supported in the Segment Builder

Rewrite using only the supported syntax, or split into multiple AND/OR conditions

Pattern works on regex101 but not in the Segment Builder

Different regex flavours — regex101 defaults to PCRE; the Segment Builder uses a more limited subset

Check your pattern against the Supported syntax table. Remove any feature not in the list

Unicode character not matched

Only 1- and 2-byte Unicode is supported

For 3- or 4-byte characters (some emoji, rare scripts), fall back to standard Contains operators


What's next?

  1. Creating a Segment — The full guide to the Segment Builder, including standard text operators (Contains, Starts with, Ends with).

  2. Segmentation Use Cases — Step-by-step examples of common Segments — many of which don't need regex.

  3. Export Profiles — Export the Profiles captured by your regex Segment.

Did this answer your question?