Skip to content

Regex Task

Overview

The Regex Task uses regular expressions to extract, validate, replace, or match patterns in text. Use it for complex data extraction, input validation, text cleaning, or pattern-based transformations.

When to use this task:

  • Extract specific patterns (emails, phones, URLs)
  • Validate input formats
  • Clean and normalize text
  • Parse structured data from unstructured text
  • Find and replace patterns
  • Split text by complex patterns
  • Extract multiple matches
  • Data scraping and parsing

Key Features:

  • Full regex pattern support
  • Multiple extraction modes
  • Capture groups
  • Find and replace
  • Match validation
  • Global and case-insensitive matching
  • Extract all matches
  • Comprehensive output fields

Outputs

Field Type Example Notes
response string ORD-5560 The first match. Only the first — there are no group_1…group_9 fields.
run boolean true false when the pattern did not match.
run_text string Pattern matched.

One match, not capture groups

The task returns the first match as a single string. To pull several values out of one piece of text, use one Regex task per value, or a Code task if you need capture groups.

Quick Start

Builder fields

The Field column is the label as it appears in the task builder; Key is the name the value is stored under and referenced by.

Field Key Type Default Notes
Input Input text –
Regex Pattern Regex Pattern monospace –
  1. Add Regex task
  2. Select operation (Extract/Replace/Match)
  3. Input text to process
  4. Write regex pattern
  5. Test with sample data
  6. Save

Simple Example:

Operation: Extract
Input: {{task_49001_message}}
Pattern: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
Output: {{task_10001_response}} = the extracted email

Operations

Extract (Most Common)

Extract data matching pattern.

Configuration:

Operation: Extract
Input: {{task_49001_text}}
Pattern: Your regex here

Output:

  • {{task_10001_response}} - the first match
  • {{task_10001_run}} - true when the pattern matched

There is no all-matches, count or found field: the task returns the first match only.

Replace

Find pattern and replace with text.

Configuration:

Operation: Replace
Input: {{task_49001_text}}
Pattern: \d{3}-\d{3}-\d{4}
Replace With: [PHONE REDACTED]

Output:

  • {{task_10001_response}} - the resulting text

Match/Validate

Check if text matches pattern.

Configuration:

Operation: Match
Input: {{task_49001_email}}
Pattern: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

Output:

  • {{task_10001_run}} - true when the input matched the pattern

Common Patterns

Email Addresses

Pattern:

[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}

Example:

Input: "Contact us at support@example.com or sales@company.org"
Output: {{task_10001_response}} → "support@example.com"
Output: {{task_10001_response}} → "support@example.com, sales@company.org"

Phone Numbers

US Format (123-456-7890):

\d{3}-\d{3}-\d{4}

International (+1-123-456-7890):

\+?\d{1,3}[-.\s]?\(?\d{1,4}\)?[-.\s]?\d{1,4}[-.\s]?\d{1,9}

Example:

Input: "Call me at 555-123-4567 or +1-555-987-6543"
Output: {{task_10001_response}} → "555-123-4567, +1-555-987-6543"

URLs

Pattern:

https?://[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(/[^\s]*)?

Example:

Input: "Visit https://example.com or http://test.org/page"
Output: {{task_10001_response}} → "https://example.com, http://test.org/page"

Numbers

Integers:

\d+

Decimals:

\d+\.\d+

Currency:

\$\d+(?:,\d{3})*(?:\.\d{2})?

Example:

Input: "Total: $1,234.56 and shipping: $45.00"
Pattern: \$\d+(?:,\d{3})*(?:\.\d{2})?
Output: {{task_10001_response}} → "$1,234.56, $45.00"

Dates

MM/DD/YYYY:

\d{2}/\d{2}/\d{4}

YYYY-MM-DD:

\d{4}-\d{2}-\d{2}

Example:

Input: "Event on 02/08/2026 or 2026-02-08"
Pattern: \d{4}-\d{2}-\d{2}
Output: {{task_10001_response}} → "2026-02-08"

Usernames/IDs

Pattern:

@[a-zA-Z0-9_]{3,20}

Example:

Input: "Mentioned @john_doe and @jane_smith in the thread"
Output: {{task_10001_response}} → "@john_doe, @jane_smith"

Order/Invoice Numbers

Pattern:

(ORD|INV)-\d{4,}

Example:

Input: "Orders ORD-5560 and INV-12345 are ready"
Output: {{task_10001_response}} → "ORD-5560, INV-12345"

Capture Groups

Extract specific parts of matches.

Example - Extract Name and Email:

Pattern: ([A-Za-z\s]+)<([^>]+)>
Input: "John Doe <john@example.com>"

Outputs:
{{task_10001_response}} → "John Doe <john@example.com>"   the first match, whole

Example - Extract Domain:

Pattern: @([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})
Input: "support@example.com"

Output:
{{task_10001_response}} → "example.com"

Example - Parse Order Details:

Pattern: Order\s+(\w+-\d+)\s+for\s+\$(\d+\.\d{2})
Input: "Order ORD-5560 for $129.99 shipped"

Outputs:
{{task_10001_response}} → "ORD-5560"

To also pull the amount, add a second Regex task with a pattern for the price.

Real-World Examples

Pull an order number out of an email

Email Trigger
  └─ Regex     pattern: (ORD|INV)-\d{4,}
      └─ Edit Client   record {{task_10001_response}} against the client

response holds the first match. If nothing matched, run is false.

Extract the sender's domain to tell business from personal

Form Submission
  └─ Regex           pattern: @([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})
      └─ Key Match   gmail.com → Personal, everything else → Business

Validate a reference before acting on it

Webhook In
  └─ Regex             pattern: ^[A-Z]{3}-\d{6}$
      └─ If Statement  run is true → continue, false → notify support

Used this way the task is a validator: run answers "does this look right?" and the workflow branches on it.

Advanced Patterns

Lookahead and Lookbehind

Extract text between markers:

Pattern: (?<=START)(.+?)(?=END)
Input: "START important data END"
Output: " important data "

Extract price without currency symbol:

Pattern: (?<=\$)\d+\.\d{2}
Input: "Total: $99.99"
Output: "99.99"

Non-Capturing Groups

Extract domain without protocol:

Pattern: https?://([a-z0-9.-]+)
Input: "https://example.com"
Output: {{task_10001_response}} → "example.com"

Alternation (OR)

Match multiple patterns:

Pattern: (Mr|Mrs|Ms|Dr)\.?\s+([A-Za-z]+)
Input: "Dr. Smith and Ms. Jones"
Outputs multiple matches with titles and names

Greedy vs Non-Greedy

Greedy (default):

Pattern: <(.+)>
Input: "<div>content</div>"
Output: "div>content</div" (matches to last >)

Non-Greedy:

Pattern: <(.+?)>
Input: "<div>content</div>"
Output: "div" (matches to first >)

Flags and Options

Case Insensitive

Match regardless of case:

Pattern: email
Flags: Case Insensitive (i)
Matches: "Email", "EMAIL", "email"

Global

Find all matches (not just first):

Pattern: \d+
Flags: Global (g)
Input: "1 2 3 4 5"
Output: {{task_10001_response}} → "1, 2, 3, 4, 5"

Multiline

^ and $ match line starts/ends:

Pattern: ^Name:.+
Flags: Multiline (m)
Matches each line starting with "Name:"

Best Practices

Pattern Design

  1. Be specific - Narrow patterns reduce false matches
  2. Test thoroughly - Use regex testers (regex101.com)
  3. Escape special characters - ., *, +, ?, [, ], (, ), {, }, ^, $, |, \
  4. Use character classes - \d for digits, \w for word chars
  5. Anchor when validating - Use ^ and $ for full string match

Performance

  1. Avoid catastrophic backtracking - Be careful with nested quantifiers
  2. Use specific patterns - \d{3} better than .+ for 3 digits
  3. Limit scope - Extract small text sections first
  4. Cache patterns - Reuse same regex in Variable task
  5. Don't overuse - Simple string operations might be faster

Maintainability

  1. Comment complex patterns - Document what pattern does
  2. Break into steps - Multiple simple regex > one complex
  3. Test edge cases - Empty strings, special characters
  4. Provide examples - Document expected inputs/outputs
  5. Version patterns - Track changes to regex patterns

Data Quality

  1. Validate before extract - Check if text exists
  2. Handle no matches - Provide defaults
  3. Trim whitespace - Clean extracted data
  4. Validate extractions - Verify format of extracted data
  5. Log failures - Track when patterns don't match

Troubleshooting

Pattern Not Matching

Check:

  1. Escape special characters (\. \$ \* etc.)
  2. Case sensitivity needed?
  3. Anchors correct (^ and $)?
  4. Pattern tested on actual data?

Debug: Test pattern at regex101.com with sample input

Too Many/Wrong Matches

Issue: Extracting unwanted text

Solutions:

  • Make pattern more specific
  • Use anchors (^ $)
  • Use non-greedy quantifiers (? after + or *)
  • Add negative lookaheads

Capture Groups Not Working

Issue: {{task_10001_response}} is empty

Check:

  • Using parentheses () for groups?
  • Pattern actually matching?
  • Accessing correct group number?

Example:

Pattern: (\d+)-(\d+)
Input: "123-456"
Group 1: "123"
Group 2: "456"

Performance Issues

Issue: Regex takes too long

Causes:

  • Catastrophic backtracking
  • Very long input text
  • Overly complex pattern

Solutions:

  • Simplify pattern
  • Use more specific character classes
  • Process smaller chunks
  • Use Code task for complex parsing

Special Characters Breaking Pattern

Issue: Pattern fails with special input

Solution: Escape special regex characters:

. → \.
* → \*
+ → \+
? → \?
[ → \[

Frequently Asked Questions

What regex flavor does BaseCloud use?

JavaScript regex (ECMAScript). Most common patterns supported.

Can I test patterns before deploying?

Yes, use regex101.com with JavaScript flavor selected.

Can I use capture groups?

Not as separate outputs. The task returns the first match in response, and there are no group_N fields. For several values from one string, use one Regex task per value, or a Code task, which gives you the full match array.

Can regex replace variables?

No, replacement is static text. Use Code task for dynamic replacements.

What if no match found?

No match: {{task_10001_run}} is false and response is empty.

Can I extract all matches separately?

Yes, use Global flag. Access via {{task_10001_response}} (comma-separated).

How to match across multiple lines?

Use Multiline flag (m) and DOTALL flag (s) if available.

Can regex parse HTML/XML?

Not recommended. Use dedicated parser or Code task with DOM methods.

How to make pattern optional?

Use ? quantifier: https? matches "http" or "https"


  • Code Task - Complex text processing
  • Formatter Task - Simple text transformations
  • If Task - Conditional logic based on regex results
  • Variable Task - Store regex results
  • Phone Formatter - Phone-specific patterns