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

# Extract with Regex Block

> Extract strings from input using regular expressions

<Frame>
  <img src="https://mintcdn.com/odella/I7v1Fbrp2kx7rLoj/block-reference/assets/extract_regex_light.png?fit=max&auto=format&n=I7v1Fbrp2kx7rLoj&q=85&s=9ea95aeaa19910174ac3bedd70fa0274" alt="Extract with Regex Block Screenshot" className="block dark:hidden" width="856" height="462" data-path="block-reference/assets/extract_regex_light.png" />

  <img src="https://mintcdn.com/odella/I7v1Fbrp2kx7rLoj/block-reference/assets/extract_regex_dark.png?fit=max&auto=format&n=I7v1Fbrp2kx7rLoj&q=85&s=4deb8b5317184c8cbb6a903cc83ac571" alt="Extract with Regex Block Screenshot" className="hidden dark:block" width="868" height="460" data-path="block-reference/assets/extract_regex_dark.png" />
</Frame>

## Overview

The Extract With Regex Block allows you to extract one or more strings from an input string using a regular expression. It's useful for parsing responses from Language Models (LLMs), extracting specific values from files, or any scenario where you need to match patterns in text.

## Key Features

* Extract multiple strings using capture groups
* Configurable error handling for failed matches
* Support for multiline mode
* Flexible output options including all matches and success/failure flags

## Inputs

<ParamField path="input" type="string" required>
  The string to match the regex against. Non-string inputs will be coerced to strings.
</ParamField>

<ParamField path="regex" type="string">
  The regular expression to use for matching. Only available when "Use Regex Input" is enabled in settings.
</ParamField>

## Outputs

<ResponseField name="output1, output2, etc" type="string">
  One output port per capture group in the regex, containing the matched content for that capture group.
</ResponseField>

<ResponseField name="matches" type="string[]">
  An array of all matched strings from the first capture group.
</ResponseField>

<ResponseField name="succeeded" type="boolean">
  True if the regex matched the input string, false otherwise.
</ResponseField>

<ResponseField name="failed" type="boolean">
  True if the regex did not match the input string, false otherwise.
</ResponseField>

## Editor Settings

<ParamField path="errorOnFailed" type="boolean" default={false}>
  If enabled, the block will error if the regex doesn't match the input string.
</ParamField>

<ParamField path="multilineMode" type="boolean" default={false}>
  Enables multiline mode for the regex, affecting `^` and `$` behavior.
</ParamField>

<ParamField path="regex" type="string" default="([a-zA-Z]+)">
  The regular expression to use for matching.
</ParamField>

<ParamField path="useRegexInput" type="boolean" default={false}>
  When enabled, allows the regex to be provided via an input port instead of being set in the settings.
</ParamField>

## Example: Extract a command from an LLM response

1. Create a Chat Block with a System Prompt:
   ```
   Your reply can initiate commands, for example `!hello` will cause "Hello world" to appear for the user. Try it out now!
   ```
2. Add an Extract With Regex Block and connect the Chat Block's output to its input.
3. Set the Regex to `!([a-zA-Z]+)`.
4. Connect the `Output 1` port to a Text Block to display the matched command.

## Error Handling

* The block will error if the input string is not provided or if the regex is invalid.
* If "Error on failed" is enabled, the block will error when the regex doesn't match the input.

## FAQ

<AccordionGroup>
  <Accordion title="How do I match a string that contains a special character?">
    For special characters like newlines, you can include them literally in the regex editor. They will be preserved in the regular expression.
  </Accordion>
</AccordionGroup>

## See Also

* [Extract Object Path Block](/block-reference/modifiers/extract-object-path)
* [Match Block](/block-reference/logic/match)
