Text Transform
The Text Node That Tells You When Your Regex Is Garbage
- text
- count
- error
Most text utility nodes in ComfyUI are a raw Python re call with no guardrails: you typo a pattern, the whole run dies, and you get to hunt through the console for why. Text Transform is the version that fails forward. It does string find/replace, regex, trim and case in one node, and when your pattern is broken it doesn't crash - it reports the error on an error output and passes your text through unchanged.
What it does
One text input, one operation dropdown, and a couple of fields that mean different things depending on the op:
replace- literal find/replace,patternis plain text.regex_replace- pattern is a real regex; reference groups as\1,\2inreplacement.regex_extract- pull the first match out.regex_findall- grab every match, joined byjoin_with(default a newline).strip- trim the characters inpattern(empty = whitespace).collapse_whitespace,lower,upper,title- need no pattern at all.
Three regex flags are optional toggles: ignorecase, multiline (^/$ match line boundaries), and dotall (. also matches newlines). Each is exactly the Python re flag with the same name, which is nice because that means no surprises if you've written regex before.
The output that saves you
text- the transformed string (or the input unchanged, on error).count- how many replacements/matches happened. Handy when you want to verify a transform did what you thought, not just eyeball it.error- a plain-language report when the pattern or a backreference is invalid. A typo never kills the run.
Why you'll reach for it
The killer use case is cleaning up LLM output before it hits a prompt. ComfyUI's local-LLM story lives on the same pack, and LLM output is full of junk - preamble, role delimiters, trailing whitespace. Running a regex_replace over a model's reply to strip markdown scaffolding is a two-node fix (LLM → Text Transform → your text encoder), and error means you can iterate on a bad regex while the workflow still runs. It also pairs with the pack's accumulators for per-iteration text cleaning.
Install
Part of the Kinburg-Nodes pack - ComfyUI Manager (search "Kinburg-Nodes"), or:
cd ComfyUI/custom_nodes
git clone https://github.com/Kinburg/Kinburg-Nodes
Restart, and it appears under Kinburg-Nodes/util. No dependencies beyond ComfyUI itself. It's the smallest kind of utility node - no models, no files, no API - so install is the whole story. If you only do literal replacements you could use ComfyUI's core string replace, but the moment you want case folding, a findall count, or an error you can read, this is the one.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | The input text (type here or wire a STRING in). | |
| operation | COMBO | replace | What to do. replace = literal; regex_* = pattern is a regular expression; strip/collapse/case need no pattern. |
| pattern | STRING | Search text (literal for 'replace'; a regex for the regex_* ops). For 'strip', the exact characters to trim (empty = whitespace). | |
| replacement | STRING | Replacement text for replace / regex_replace. In regex_replace you may reference groups as \1, \2, … | |
| ignorecaseopt | BOOLEAN | false | Regex ops: case-insensitive matching (re.IGNORECASE). |
| multilineopt | BOOLEAN | false | Regex ops: ^ and $ match at line boundaries (re.MULTILINE). |
| dotallopt | BOOLEAN | false | Regex ops: '.' also matches newlines (re.DOTALL). |
| join_withopt | STRING | regex_findall: string inserted between matches. Default is a newline. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |
| count | INT | — |
| error | STRING | — |