Text Replacer
Find-and-replace for prompts, regex mode included
- text
This is the node in the String Utils pack with actual teeth. The formatters and converters are plumbing; Text Replacer is where you clean up, transform, and restructure text - and the mode switch to regex is what makes it more than a find-and-replace. If you've ever wanted to strip a tag out of every prompt, swap a character name across a workflow, or do a pattern-based rewrite, this is the node.
What it does
Three text inputs and a mode selector. Give it the source text, a replace pattern, and a replacement, and it returns the transformed string.
- normal mode - literal string replacement.
text.replace(replace, replacement). "John" → "Mr. Smith", everywhere it appears. - regex mode -
re.sub(replace, replacement, text). Thereplacefield is a regular expression, andreplacementcan use backreferences to captured groups.
The README's regex example is the one to internalize: with replace="([0-9]+) is" and replacement="\1 is in fact", the text "42 is the answer" becomes "42 is in fact the answer" - the \1 pulls the captured 42 into the replacement. That pattern - match a chunk, keep part of it, swap the rest - is genuinely powerful for prompt cleanup.
The inputs that matter
- text - what you're transforming.
- replace - what to find: a literal string in normal mode, a regex pattern in regex mode.
- replacement - what to put in its place.
- mode - dropdown,
normal(default) orregex.
Output: text, the transformed STRING.
How to install it
Part of exectails/comfyui-et_stringutils ("String Utils"). ComfyUI Manager → search "String Utils", or:
cd ComfyUI/custom_nodes
git clone https://github.com/exectails/comfyui-et_stringutils
Restart, and it's under exectails/Strings. No dependencies, no model downloads - the only library it touches is Python's built-in re module.
Common issues
- Normal mode is literal. Put
"("in the replace field in normal mode and it looks for a literal parenthesis. Regex metacharacters only act like patterns in regex mode. If your text contains regex characters and you're not intending a pattern, stay in normal mode. - Invalid regex = crash. A malformed pattern (say, an unclosed
() raises an error and kills the run. Test your pattern elsewhere first if it's gnarly. - No matches is not an error.
re.subandstr.replaceboth return the text unchanged when nothing matches - the node just passes it through. That's usually what you want, and it means a missing tag in your data won't take the whole workflow down. - Backreference syntax.
\1works in the replacement for regex mode (that's what the README shows), and\g<1>works too. Note those backslashes are meaningful only in regex mode - in normal mode\1is a literal backslash-one.
Use it to strip stray tags, normalize whitespace, swap names, or build a regex-powered cleaning stage between your prompt source and the encoder. It's the utility node that quietly saves you from editing prompts by hand.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | The text to replace in. | |
| replace | STRING | The text to replace. | |
| replacement | STRING | The text to replace with. | |
| mode | COMBO | normal | The mode to use for replacing. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |