Nodes/ComfyUI-GTSuya-Nodes/Replace Strings
ComfyUI Node

Replace Strings

Find-and-replace for your ComfyUI prompts, no regex required

By GTSuya-Studio·Created 3 years ago·Updated 4 months ago· 14
Replace Strings
    • text
    text
    replace_list

    Wildcards spit out a random line, an LLM prompt-writer spits out a paragraph, a template node spits out a half-finished sentence with leftover placeholder text in it - and now you've got a string full of junk you didn't want. Replace Strings is the cleanup pass: point it at any text, give it a list of things to swap or delete, and it hands back a clean string ready for CLIP Text Encode. It's not glamorous. It's also the node you reach for once a week without thinking about it, because prompt text going through two or three generator nodes before it hits the sampler is completely normal in a wildcard-heavy workflow, and something in that chain always needs a small fix.

    How it works

    Two text inputs, one text output. text is whatever you want cleaned up - usually the output of a wildcard node, a string concat, or an LLM prompt node upstream. replace_list is your instruction set, one rule per line, in the form string1|string2. The node reads it top to bottom and swaps every string1 it finds for string2. Leave off the second half - just string1 on its own - and it deletes that string instead of replacing it. That's the whole feature. No regex, no wildcards inside the replacement rules, just literal substring matching.

    Where that earns its keep: a wildcards file gives you messy hair|bedhead on one line to normalize vocabulary across a big wildcard library without editing every .txt file. Or you're stripping a stray __missing__ token that a broken wildcard link left behind. Or an LLM prompt-writer keeps prefacing its output with "Here's your prompt:" and you want that gone before it hits the encoder - Here's your prompt: on its own line in replace_list, done.

    Inputs and output

    Just the two required fields, both plain STRING:

    • text - the string to clean. Wire in a wildcard node's output, a prompt string, whatever needs fixing.
    • replace_list - your rules, one string1|string2 (or bare string1 to delete) per line.

    Output is a single text (STRING) - wire it straight into CLIP Text Encode or into whatever's next in the chain.

    Installing it

    ComfyUI Manager: search ComfyUI-GTSuya-Nodes, install, restart. Or by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/GTSuya-Studio/ComfyUI-Gtsuya-Nodes.git
    

    Restart ComfyUI. No model downloads, no extra Python dependencies - it's a plain string node, so there's nothing to fetch after the clone.

    Where people get burned

    Matching is case-sensitive and literal, so Cat|Dog won't touch cat - if your wildcard files aren't consistent about capitalization, write both cases into replace_list rather than assuming one rule covers it. The bigger trap is rule order: since it reads replace_list top to bottom and each rule operates on the already-modified text, an earlier rule can eat the substring a later rule was supposed to match. If a replacement isn't taking effect, check whether an earlier line already changed that part of the text out from under it. And because matching is substring-based, not word-based, a short rule like art|illustration will also fire inside longer words (artistillustrationist) - keep your replacement strings specific enough, or pad them with spaces (" art "|" illustration ") to force a whole-word match.

    CategoryGtsuyaStudio/Tools

    Inputs (2)

    NameTypeDefaultDescription
    textSTRING
    replace_listSTRING

    Outputs (1)

    NameTypeDescription
    textSTRING