- Phone numbers (
(123) 456-7890) - Email addresses (
user@example.com) - Product codes (
ABC-123-XYZ)
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.
- Avoid conflicts with Lexicon Slots and System Slots by ensuring unique Slot names.
Working with Regex Slots
To start working with Regex Slots, you can use one of the following options:- Apply to an Entire Flow
- Apply After a Specific Point in a Flow
To define a regex pattern that runs on all user inputs in the Flow, follow these steps:
- In the Flow editor, go to NLU > Slot Fillers.
- In the upper-left corner, click + New Slot Filler.
- In the New Slot Filler window, 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. Patterns must start and end with
/. Flags likegfor global matching aren’t supported. - Context Key – enter a Slot name to store the matched data in the Context object. For example,
phone_number.
- Name – enter a unique name for the Slot Filler. For example,
Example
These examples show how regex patterns fill Slots in the Context object.Single Match
Single Match
User Input:
Regex Pattern:
Slot Name:
Result: The
My phone number is 555-123-4567Regex Pattern:
/\d{3}-\d{3}-\d{4}/Slot Name:
phone_numberResult: The
context.phone_number Slot is filled with 555-123-4567. The AI Agent responds Thanks for providing your phone number: {{context.slots.phone_number}}!Multiple Matches
Multiple Matches
When the user input contains multiple values that match the pattern, only the first match is stored.User Input:
Regex Pattern:
Slot Name:
Result: The
The booking codes are 123456 and 789123Regex Pattern:
/\b\d{6}\b/Slot Name:
booking_codesResult: The
context.booking_codes Slot is filled with 123456.Use Cases
- Extracting a booking code:
/^[A-Z]{3}-\d{4}$/to captureXYZ-1234. - Capturing email addresses with the
@companydomain:/^[a-zA-Z0-9._%+-]+@company\.com$/. - Identifying dates in specific formats:
/^\d{2}\/\d{2}\/\d{4}$/for04/22/2025.