Nodes/Kinburg-Nodes/Text Transform
ComfyUI Node

Text Transform

The Text Node That Tells You When Your Regex Is Garbage

By Kinburg·Created 3 months ago·Updated 6 days ago· 1
Text Transform
    • text
    • count
    • error
    text
    operationreplace
    pattern
    replacement
    ignorecasefalse
    multilinefalse
    dotallfalse
    join_with

    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, pattern is plain text.
    • regex_replace - pattern is a real regex; reference groups as \1, \2 in replacement.
    • regex_extract - pull the first match out.
    • regex_findall - grab every match, joined by join_with (default a newline).
    • strip - trim the characters in pattern (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.

    CategoryKinburg-Nodes/util

    Inputs (8)

    NameTypeDefaultDescription
    textSTRINGThe input text (type here or wire a STRING in).
    operationCOMBOreplaceWhat to do. replace = literal; regex_* = pattern is a regular expression; strip/collapse/case need no pattern.
    patternSTRINGSearch text (literal for 'replace'; a regex for the regex_* ops). For 'strip', the exact characters to trim (empty = whitespace).
    replacementSTRINGReplacement text for replace / regex_replace. In regex_replace you may reference groups as \1, \2, …
    ignorecaseoptBOOLEANfalseRegex ops: case-insensitive matching (re.IGNORECASE).
    multilineoptBOOLEANfalseRegex ops: ^ and $ match at line boundaries (re.MULTILINE).
    dotalloptBOOLEANfalseRegex ops: '.' also matches newlines (re.DOTALL).
    join_withoptSTRING regex_findall: string inserted between matches. Default is a newline.

    Outputs (3)

    NameTypeDescription
    textSTRING
    countINT
    errorSTRING