Skip to main content
Regex slots are user-defined slots that apply regular expressions (regex) to match and extract specific patterns from user inputs. Unlike lexicon slots, which rely on keyphrases, regex slots are ideal for structured data that follows a predictable format, such as:
  • Phone numbers ((123) 456-7890).
  • Email addresses (user@example.com).
  • Product codes (ABC-123-XYZ).
You can use regex slots only as slot fillers.

Recommendations

  • Regex slots require careful crafting to avoid overly broad or restrictive patterns.
  • Complex regular expressions can be error-prone. Test them thoroughly to avoid missing matches or capturing incorrect data.
  • Ensure unique slot names to avoid conflicts with lexicon slots and system slots.

Work with regex slots

To start working with regex slots, you can use one of the following options:
To define a regex pattern that runs on all user inputs in the flow, follow these steps:
  1. Go to Advanced > NLU > Slot Fillers.
  2. In the upper-left corner, click + New Slot Filler.
  3. In the New Slot Filler sidebar, fill in the following fields:
    • Name. Enter a unique name for the slot filler. For example, phone_number.
    • Type. Select Regular Expression.
    • Regular Expression. Enter a regex pattern in the format /pattern/flags, for example, /\d{3}-\d{3}-\d{4}/i. Flags are optional. The slot filler stores only the first match, so the g flag has no effect.
    • Store result in Context. In the Advanced section, activate this toggle.
    • Context Key. Enter a key to store the matched data in the Context object. For example, phone_number.

Example

These examples show how a regex slot filler stores a match in the Context object. In both examples, Store result in Context is activated.
User input: My phone number is 555-123-4567
Regex pattern: /\d{3}-\d{3}-\d{4}/
Context Key: phone_number
Result: context.phone_number is filled with 555-123-4567. The agent responds with Thanks for providing your phone number: {{context.phone_number}}!
When the user input contains multiple values that match the pattern, only the first match is stored.User input: The booking codes are 123456 and 789123
Regex pattern: /\b\d{6}\b/
Context Key: booking_codes
Result: context.booking_codes is filled with 123456.

Use cases

  • Extracting a booking code: /^[A-Z]{3}-\d{4}$/ to capture XYZ-1234.
  • Capturing email addresses with the @company domain: /^[a-zA-Z0-9._%+-]+@company\.com$/.
  • Identifying dates in specific formats: /^\d{2}\/\d{2}\/\d{4}$/ for 04/22/2025.

More information

Last modified on November 11, 2026