Match Regex
Extract data from text using powerful regular expressions. Perfect for validation, pattern matching, and data extraction.
Overview
Section titled “Overview”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.
Configuration
Section titled “Configuration”Input Fields
Section titled “Input Fields”Text (Required)
Section titled “Text (Required)”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-15Pattern (Required)
Section titled “Pattern (Required)”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+)Flags (Optional)
Section titled “Flags (Optional)”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
Output Fields
Section titled “Output Fields”matched (Boolean String)
Section titled “matched (Boolean String)”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
matchedText (String)
Section titled “matchedText (String)”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
Common Patterns
Section titled “Common Patterns”Email Validation
Section titled “Email Validation”[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}Phone Numbers
Section titled “Phone Numbers”\d{3}-\d{3}-\d{4}Matches: 555-123-4567
https?://[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}Use Cases
Section titled “Use Cases”Validate Email Format
Section titled “Validate Email Format”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
Extract Order Number from Text
Section titled “Extract Order Number from Text”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
Validate Phone Number Format
Section titled “Validate Phone Number Format”Input:
- Text:
{{contact.phone}} - Pattern:
^\\d{3}-\\d{3}-\\d{4}$
Output:
- matched:
"true"if format is 555-123-4567 - matchedText: The phone number
Extract Domain from Email
Section titled “Extract Domain from Email”Input:
- Text:
john.doe@example.com - Pattern:
@([a-zA-Z0-9.-]+)
Output:
- matched:
"true" - matchedText:
example.com
Check for Specific Keywords
Section titled “Check for Specific Keywords”Input:
- Text:
{{ticket.subject}} - Pattern:
urgent|emergency|critical - Flags:
i
Output:
- matched:
"true"if any keyword found (case-insensitive) - matchedText: The matched keyword
Best Practices
Section titled “Best Practices”- 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