Nodes/ComfyUI_StringOps/批量替换字符🐠meeeyo.com
ComfyUI Node

批量替换字符🐠meeeyo.com

Run a whole dictionary of text replacements in one pass

By MeeeyoAI·Created 2 years ago·Updated about a year ago· 209
批量替换字符🐠meeeyo.com
    • STRING
    original_text文本内容
    replacement_rules

    BatchReplaceStrings applies a whole list of find-and-replace rules to a string in one pass, which makes it the pack's answer to "I have a vocabulary of things I always want scrubbed or rewritten." Paste your rules in, get one cleaned STRING out. It's part of MeeeyoAI/ComfyUI_StringOps and sits at the "batch automation" end of the pack's pitch.

    The README's first headline feature is batch replacement, and this is that node: where SimpleTextReplacer swaps one pair, this one runs as many rules as you can write. Typical jobs: strip a set of unwanted tokens from every prompt (ugly, deformed, blurry| removes them), normalize spelling variants to one canonical term, or map a list of shorthand codes to their full prompt phrases before encoding.

    The two inputs

    • original_text - the text to transform. Note the schema marks it not multiline, so paste your single block here without worrying about it growing its own newlines.
    • replacement_rules - the multiline rule list. The format per line is search|replacement:
      cat|dog
      ugly,deformed|beautiful
      bad hands|good hands
      
      And the multiplier that makes this node worth it: the search side can itself be comma-separated, mapping several strings to one replacement. worst quality,lowres,blurry| strips all three at once.

    How it works - and the order trap

    Rules apply sequentially, top to bottom. Each rule's output is what the next rule sees. That's powerful - you can chain transformations - and it's also the classic footgun. If rule one turns cat into dog, rule two's search for cat will find nothing, and rule two's search for dog will hit rule one's output. Order your rules the way a pipeline would: destructive cleanup first, then rewrites. Also, replacements are plain string swaps, so cat inside category gets replaced too - there's no word-boundary logic. Escape literal newlines in your rules as \n, which the node converts for you.

    The comma-splitting on the search side has one obvious limitation: you can't search for a comma this way. A rule whose search contains a comma will be split into multiple searches, which is rarely what you meant. Keep comma searches to the replacement side.

    Wiring it

    Run it after RandomLineFromText or before a CLIP Text Encode: draw a raw line, scrub it through your rules, feed the result to encoding. It's also handy for sanitizing text pulled in from files before it hits the prompt pipeline.

    Installing

    Standard pack install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MeeeyoAI/ComfyUI_StringOps.git
    

    or via ComfyUI Manager searching ComfyUI_StringOps, then restart. Under "Meeeyo/String". No models, no dependencies to install.

    It's a genuinely useful batch tool hiding behind a modest surface. Just remember the rule order matters, and that comma-separated searches are the node's way of doing multi-to-one mapping.

    CategoryMeeeyo/String

    Inputs (2)

    NameTypeDefaultDescription
    original_textSTRING文本内容
    replacement_rulesSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING