ComfyUI > Nodes > ComfyUI > Replace Text (Regex)

ComfyUI Node: Replace Text (Regex)

Class Name

RegexReplace

Category
text
Author
ComfyAnonymous (Account age: 763days)
Extension
ComfyUI
Latest Updated
2026-05-13
Github Stars
112.77K

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

Replace Text (Regex) Description

Facilitates advanced text manipulation by searching for patterns in a string and replacing them using regular expressions.

Replace Text (Regex):

The RegexReplace node is designed to facilitate advanced text manipulation by allowing you to search for specific patterns within a string and replace them with a desired text. This node leverages regular expressions (regex), a powerful tool for pattern matching, to identify and substitute text efficiently. It is particularly beneficial for tasks that require dynamic text editing, such as formatting, cleaning up data, or transforming text based on complex criteria. By using this node, you can automate the process of finding and replacing text patterns, which can significantly enhance productivity and accuracy in text processing tasks.

Replace Text (Regex) Input Parameters:

string

This parameter represents the input text where the regex pattern will be applied. It is the source text that you want to search through and modify. There are no specific minimum or maximum values for this parameter, as it can be any string of text.

regex_pattern

This parameter is the regular expression pattern used to search within the input string. It defines the criteria for matching text segments that need to be replaced. The pattern can be as simple or complex as needed, depending on the text manipulation task. There are no specific minimum or maximum values, but it should be a valid regex pattern.

replace

This parameter specifies the text that will replace the matched patterns in the input string. It allows you to define what the matched text should be transformed into. There are no specific constraints on this parameter, as it can be any string of text.

case_insensitive

This boolean parameter determines whether the regex search should ignore case differences. If set to True, the search will be case-insensitive, meaning it will match text regardless of case. The default value is True.

multiline

This boolean parameter specifies whether the regex pattern should treat the input string as multiple lines. If set to True, the ^ and $ anchors will match the start and end of each line, respectively, rather than the start and end of the entire string. The default value is False.

dotall

This boolean parameter controls whether the dot (.) in the regex pattern should match newline characters. If set to True, the dot will match any character, including newlines. The default value is False.

count

This parameter specifies the maximum number of pattern occurrences to replace. If set to 0, all occurrences will be replaced. The default value is 0.

Replace Text (Regex) Output Parameters:

result

This output parameter provides the modified string after the regex pattern has been applied and the specified replacements have been made. It reflects the input string with all the matched patterns replaced according to the defined criteria, offering a transformed version of the original text.

Replace Text (Regex) Usage Tips:

  • Use the case_insensitive parameter to ensure your regex pattern matches text regardless of case, which is useful for general text processing tasks.
  • Leverage the multiline and dotall parameters to handle complex text structures, such as multi-line documents or text blocks with varying line breaks.
  • Experiment with different regex patterns to achieve precise text transformations, and test them using online regex testers to ensure accuracy before applying them in the node.

Replace Text (Regex) Common Errors and Solutions:

Invalid regular expression

  • Explanation: This error occurs when the regex pattern provided is not valid, possibly due to syntax errors or unsupported constructs.
  • Solution: Review the regex pattern for any syntax errors or unsupported features. Use online regex testers to validate and refine your pattern before using it in the node.

Replacement string not applied

  • Explanation: This issue arises when the regex pattern does not match any part of the input string, resulting in no replacements being made.
  • Solution: Double-check the regex pattern to ensure it accurately represents the text you intend to match. Adjust the pattern or input string as necessary to achieve the desired matches.

Replace Text (Regex) 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 Models, enabling artists to harness the latest AI tools to create incredible art.

Replace Text (Regex)