> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cognigy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Regex Slots

*Regex Slots* are user-defined Slots, which apply [regular expressions](https://regex101.com/) (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 this type of Regex Slots only as [Slot Fillers](/ai/platform-features/nlu/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.
* 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:

<Tabs>
  <Tab title="Apply to an Entire Flow">
    To define a regex pattern that runs on all user inputs in the Flow, follow these steps:

    1. In the Flow editor, go to **NLU > Slot Fillers**.
    2. In the upper-left corner, click **+ New Slot Filler**.
    3. 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 like `g` for global matching aren't supported.
       * **Context Key** – enter a Slot name to store the matched data in the Context object. For example, `phone_number`.
  </Tab>

  <Tab title="Apply After a Specific Point in a Flow">
    To define a regex pattern that runs after a specific user input in the Flow, follow these steps:

    1. In the Flow editor, add a [Regex Slot Filler](/ai/agents/develop/node-reference/ai/regex-slot-filler) Node where you want to process the input, for example, after a Question Node.
    2. In the Node editor, configure the following fields:
       * **Regular Expression** - enter a regex pattern without leading and trailing slashes, for example, `^\d{3}-\d{3}-\d{4}$`.
       * **Flags** – enter flags you want to apply to the regular expression, for example, `i` for case-insensitive, `m` for multiline. Note that the `g` flag should always be specified.
       * **Slot Name** – enter the Slot name to store the matched data in the `slots.<slot-name>` Input object. For example, `phone_number`.

    Once a Regex Slot is filled, the extracted data can be used in the conversation logic, for example, for the following purposes:

    * Validating user input, for example, ensuring a valid email format.
    * Triggering specific actions, for example, saving a phone number to the Contact Profile.
    * Combining with Question Nodes to prompt users to re-enter missing or incorrectly formatted information.
  </Tab>
</Tabs>

### Example

These examples show how regex patterns fill Slots in the Context object.

<AccordionGroup>
  <Accordion title="Single Match">
    **User Input**: `My phone number is 555-123-4567`<br />
    **Regex Pattern**: `/\d{3}-\d{3}-\d{4}/`<br />
    **Slot Name**: `phone_number`<br />
    **Result**: 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}}!`
  </Accordion>

  <Accordion title="Multiple Matches">
    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`<br />
    **Regex Pattern**: `/\b\d{6}\b/`<br />
    **Slot Name**: `booking_codes`<br />
    **Result**: The `context.booking_codes` Slot is filled with `123456`.
  </Accordion>
</AccordionGroup>

## 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

* [Lexicon Slots](/ai/platform-features/nlu/slots/user-defined/lexicon)
* [Overview](/ai/platform-features/nlu/slots/user-defined/overview)
* [System-Defined](/ai/platform-features/nlu/slots/system-defined)
