Skip to content

Match Regex

Extract data from text using powerful regular expressions. Perfect for validation, pattern matching, and data extraction.

The Match Regex action allows you to test if text matches a regular expression pattern and extract the first match. Use it to validate formats (like emails or phone numbers), extract patterns from text, or check if text contains specific patterns for conditional workflow branching.

The text you want to search or validate. This can be any string value from a contact property, workflow variable, or static text.

Example:

{{contact.email}}
{{contact.phone}}
Order #12345 shipped on 2024-01-15

The regular expression pattern to match against the text. Use standard regex syntax.

Important: In HubSpot workflows, use \\ instead of \ for escape sequences (e.g., \\d for digits, \\s for whitespace).

Example:

[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}
\\d{3}-\\d{3}-\\d{4}
Order #(\\d+)

Regex flags to modify matching behavior:

  • i - Case insensitive matching
  • g - Global matching (find all matches)
  • m - Multiline matching
  • s - Dot matches newlines

Example: i for case-insensitive, ig for case-insensitive and global

Returns "true" if the pattern was found in the text, "false" otherwise. Use this in if/then branches to control workflow logic.

Example values:

  • "true" - Pattern was found
  • "false" - Pattern was not found

The actual text that matched the pattern. If the pattern includes capture groups (), returns the first captured group. Returns empty string if no match.

Example:

  • Pattern: Order #(\\d+)
  • Text: Order #12345 shipped
  • Result: 12345
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
\d{3}-\d{3}-\d{4}

Matches: 555-123-4567

https?://[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}

Input:

  • Text: {{contact.email}}
  • Pattern: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}

Output:

  • matched: "true" or "false"
  • matchedText: The email address if valid

Workflow Branch: If matched = “true”, continue with email marketing

Input:

  • Text: Your order #ORD-12345 has shipped
  • Pattern: ORD-(\\d+)

Output:

  • matched: "true"
  • matchedText: 12345

Use: Save matchedText to a custom property for order tracking

Input:

  • Text: {{contact.phone}}
  • Pattern: ^\\d{3}-\\d{3}-\\d{4}$

Output:

  • matched: "true" if format is 555-123-4567
  • matchedText: The phone number

Input:

  • Text: john.doe@example.com
  • Pattern: @([a-zA-Z0-9.-]+)

Output:

  • matched: "true"
  • matchedText: example.com

Input:

  • Text: {{ticket.subject}}
  • Pattern: urgent|emergency|critical
  • Flags: i

Output:

  • matched: "true" if any keyword found (case-insensitive)
  • matchedText: The matched keyword
  • Test patterns first - Use regex testers like regex101.com to validate patterns
  • Start simple - Begin with basic patterns and add complexity as needed
  • Remember escaping - Use \\ instead of \ in HubSpot (e.g., \\d, \\s, \\w)
  • Branch on matched - Use the matched output for if/then logic
  • Use capture groups - Wrap parts you want to extract in parentheses ()
  • Anchor patterns - Use ^ (start) and $ (end) for exact matches
  • Test edge cases - Try empty strings, special characters, and long text