ComfyUI > Nodes > ComfyUI > Regex Extract

ComfyUI Node: Regex Extract

Class Name

RegexExtract

Category
utils/string
Author
ComfyAnonymous (Account age: 872days)
Extension
ComfyUI
Latest Updated
2025-05-13
Github Stars
76.71K

How to Install ComfyUI

Install this extension via the ComfyUI Manager by searching for ComfyUI
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter ComfyUI in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • 16GB VRAM to 80GB VRAM GPU machines
  • 400+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 200+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

Regex Extract Description

Extract specific patterns from text using regular expressions for data parsing and manipulation.

Regex Extract:

The RegexExtract node is designed to help you extract specific patterns from a given string using regular expressions, a powerful tool for pattern matching. This node is particularly useful when you need to isolate or retrieve specific parts of text data, such as extracting email addresses, phone numbers, or any other pattern-based information from a larger body of text. By leveraging the capabilities of regular expressions, the RegexExtract node allows you to perform complex text extraction tasks with ease, making it an essential tool for data parsing and text manipulation. Whether you're working with structured or unstructured data, this node provides a flexible and efficient way to extract the information you need.

Regex Extract Input Parameters:

string

This parameter represents the input text from which you want to extract patterns. It can be a single line or multiline string, depending on the nature of your data. The content of this parameter is crucial as it serves as the source from which the regular expression will search for matches.

regex_pattern

The regex_pattern parameter is a string that defines the regular expression pattern you want to use for extraction. This pattern dictates what the node will look for in the input string. Regular expressions are highly versatile, allowing you to specify complex search criteria using a combination of literals, metacharacters, and quantifiers.

mode

This parameter determines the extraction mode, which can be "First Match," "All Matches," "First Group," or "All Groups." Each mode specifies a different way of extracting data: "First Match" retrieves the first occurrence of the pattern, "All Matches" retrieves all occurrences, "First Group" extracts the first capturing group from the first match, and "All Groups" extracts a specific group from all matches.

case_insensitive

A boolean parameter that, when set to True, makes the regular expression search case-insensitive, meaning it will ignore the case of the characters in the input string. The default value is True, which is useful when you want to ensure that the search is not affected by the case of the text.

multiline

This boolean parameter, when set to True, allows the ^ and $ anchors in the regular expression to match the start and end of each line within the input string, rather than just the start and end of the entire string. The default value is False.

dotall

When this boolean parameter is set to True, the dot (.) in the regular expression will match any character, including newline characters. This is useful when you want to match patterns that span multiple lines. The default value is False.

group_index

This parameter is an integer that specifies which capturing group to extract when using the "First Group" or "All Groups" modes. It allows you to target specific parts of the matched pattern, providing more granular control over the extraction process.

Regex Extract Output Parameters:

result

The result parameter contains the extracted text based on the specified mode and regular expression pattern. If the mode is "First Match," it will return the first occurrence of the pattern. For "All Matches," it returns all occurrences, joined by a newline. In "First Group" mode, it returns the specified capturing group from the first match, and in "All Groups" mode, it returns the specified group from all matches, also joined by a newline. If no matches are found, the result will be an empty string.

Regex Extract Usage Tips:

  • Use the "First Match" mode when you only need the first occurrence of a pattern, which can improve performance by stopping the search early.
  • When working with multiline text, consider enabling the multiline parameter to ensure that line boundaries are correctly interpreted by the regular expression.
  • If your pattern needs to match across multiple lines, set the dotall parameter to True to allow the dot (.) to match newline characters.
  • Utilize the group_index parameter to extract specific parts of a match, especially when dealing with complex patterns that include multiple capturing groups.

Regex Extract Common Errors and Solutions:

Invalid regular expression

  • Explanation: This error occurs when the regex_pattern contains syntax errors or unsupported constructs.
  • Solution: Double-check the regular expression for any typos or unsupported syntax. Use online regex testers to validate your pattern before using it in the node.

IndexError: no such group

  • Explanation: This error happens when the group_index specified does not exist in the matched pattern.
  • Solution: Ensure that the group_index corresponds to an existing capturing group in your regular expression. Adjust the index based on the number of groups in your pattern.

No matches found

  • Explanation: This occurs when the regular expression does not find any matches in the input string.
  • Solution: Verify that the regex_pattern is correctly defined and matches the intended parts of the input string. Consider adjusting the pattern or enabling case_insensitive if case sensitivity is an issue.

Regex Extract Related Nodes

Go back to the extension to check out more related nodes.
ComfyUI
RunComfy
Copyright 2025 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Playground, enabling artists to harness the latest AI tools to create incredible art.