ComfyUI Node

Text Pipe #39

The Tiny Regex Gate That Decides Your Prompt for You

By shinich39·Created 57 years ago·Updated 57 years ago· 2
Text Pipe #39
    • text
    • int
    textBanana
    pattern^Banana$
    output_mode
    true
    false

    The name sounds like something you'd pull from a blind-box gacha set, but "Text Pipe #39" is just a tiny utils node by shinich39 that does one thing: modify text by condition. Feed it a string, give it a regular expression, and it decides which of two replacement strings to hand back - then optionally rewrites your text with that string. If you've ever wanted one prompt to quietly branch into another depending on something you can test with regex, this is the node for it.

    What it actually does

    Text routing in ComfyUI is usually a clumsy dance: two CLIP Text Encoders, a switch node, maybe a ShowText you check with your eyeballs. This node collapses that into a single box. The mechanism is simple:

    1. text comes in (the string you're testing).
    2. pattern - a JavaScript regular expression - is tested against it.
    3. Match → the true string wins. No match → the false string wins.
    4. output_mode decides how that winning string gets used.

    The default state is a live example: text = "Banana", pattern = ^Banana$. That pattern matches the whole string, so the true branch is active the moment you add the node. Wire nothing, run it, and you'll see exactly which branch your input took.

    The four output modes

    • change - the winning string replaces the entire input. Banana + pattern match + true = "Apple". This is the "decide the whole prompt" mode.
    • append - the winning string goes on the end: "Banana" + " pie".
    • prepend - the winning string goes in front: "tasty " + "Banana".
    • replace - the winning string swaps out just the matched portion of the text, which is the mode you want when your pattern targets a substring and you want to keep the rest.

    Honestly, change is the one you'll reach for 90% of the time. The other three exist for when you're mutating, not replacing.

    The inputs that matter

    For a beginner, only three fields matter. text is what you're testing, pattern is your regex, and output_mode is your behavior. The true and false strings are just values - leave both empty and every mode except change hands back your original text unchanged.

    Wiring the outputs

    There are two outputs, and they're the whole point. text is the transformed string - feed it straight into a CLIP Text Encoder (Positive Prompt) and you've made your prompt conditional. int is the match flag: 1 when the pattern matched, 0 when it didn't. That's your routing signal - send it into a switch or a conditioning-select node to flip between whole downstream paths based on what the regex saw.

    Installing it

    No dependencies, no model downloads, no requirements.txt - this is pure string logic. Try ComfyUI Manager first (search "comfyui-text-pipe-39"), or clone it manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/shinich39/comfyui-text-pipe-39
    

    Restart ComfyUI, then look under Add node > utils > Text Pipe #39.

    Where people get stuck

    The big one, and it's not your fault: the GitHub repo is currently returning a 404. The author maintains a whole numbered series of small utility nodes, and this one appears to have been removed or made private at the time of writing - it's not in the Manager registry either. If your clone fails with a not-found error, that's why. Don't rebuild your entire workflow around a pack that may not be coming back.

    Two more practical traps, both about the regex. First, this is JavaScript regex (the README links to MDN's JS guide), not Python's re. Most ComfyUI text tools use Python regexes, so patterns you copy-paste from a Python node can silently behave differently - escapes and ^/$ semantics aren't identical. Second, watch your anchors: ^Banana$ matches the whole string, but plain Banana matches anywhere, so the same pattern can flip your int output depending on how strictly you wrote it.

    Categoryutils

    Inputs (5)

    NameTypeDefaultDescription
    textSTRINGBanana
    patternSTRING^Banana$
    output_modeCOMBO4 options: change, append, prepend, replace
    trueSTRING
    falseSTRING

    Outputs (2)

    NameTypeDescription
    textSTRING
    intINT