Nodes/comfyui-AGSoft/AGSoft Text Replace
ComfyUI Node

AGSoft Text Replace

Find-and-replace for prompts, with up to three swaps in one pass

By Art-xmaster·Created 12 months ago·Updated a day ago· 23
AGSoft Text Replace
    • STRING
    text
    find1
    replace1
    case_sensitive1true
    whole_word1false
    find2
    replace2
    case_sensitive2true
    whole_word2false
    find3
    replace3
    case_sensitive3true
    whole_word3false

    "Replace all" is something you expect from a text editor, not a ComfyUI node - until you're cleaning up danbooru tags or normalizing a batch of prompts and realize there's no built-in for it. AGSoft Text Replace from comfyui-AGSoft fixes that with one text input, up to three find/replace pairs, and per-pair case-sensitivity and whole-word toggles. One node replaces the pile of chained text nodes you were about to build.

    How it works

    Mechanically it's Python's re.sub under a friendly wrapper, and the implementation choices are smart ones:

    • Your find strings are re.escaped, so special characters like ., *, or ( are treated literally - no regex surprises unless you intentionally use the features below.
    • case_sensitive toggles re.IGNORECASE (default on, so it behaves like a plain search).
    • whole_word wraps the pattern in \b word boundaries, so find="cat" with whole-word on matches "the cat" but not "catalog".

    The three pairs - find1/replace1, find2/replace2, find3/replace3 - each with their own case_sensitive and whole_word booleans, run in order 1 → 3. Empty find fields are skipped entirely, so you can leave pair 2 and 3 blank and use this as a plain single-replace node.

    What you'll actually set

    Honestly, just three fields most of the time: text, find1, and replace1. The whole-word and case-sensitivity toggles matter when you're editing natural-language prompts - replacing "cat" without whole-word will happily mangle "catwoman" into "dogwoman". The second and third pairs earn their keep when you're normalizing a long tag string, like swapping three synonyms in one pass instead of chaining nodes.

    The single output is a STRING, which feeds straight into whatever downstream text consumer you have - a CLIP Text Encode, a Show Text node for checking, or another replacement pass.

    Where you'd reach for it

    • Scrubbing a prompt: strip negative phrases, replace best quality with masterpiece, drop artist names you don't want.
    • Translating a style vocabulary - map English tags to whatever the model was trained with.
    • Tag cleanup on captioned datasets before a training run.

    It's a small node with a boring job, which is exactly why it's worth having.

    Installing it

    It's part of the big comfyui-AGSoft utility pack, so install once and everything comes along:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Art-xmaster/comfyui-AGSoft.git
    # restart ComfyUI
    

    Or search comfyui-AGSoft in ComfyUI Manager. No models, no heavy deps - this one is pure Python re, so nothing extra to install.

    Gotchas

    The big one is order. Replacements run sequentially, and pair 2 operates on the output of pair 1. If your patterns overlap, results depend on the order you list them - which is a feature once you know it, and a bug until you do.

    Two smaller ones: whole-word matching uses \b boundaries, so it plays well with spaces and punctuation but won't help you with underscore-heavy tag strings. And because it's built on re.sub, a backslash in a replace string is treated as an escape - fine for real use, but don't go hunting for a bug in your own backslashes. That's really the whole failure surface; there isn't much else to trip on.

    CategoryAGSoft/Text

    Inputs (13)

    NameTypeDefaultDescription
    textSTRINGThe original text in which to perform replacements. Исходный текст, в котором будут выполняться замены.
    find1STRINGThe substring to find for the first replacement. Подстрока, которую нужно найти для первой замены.
    replace1STRINGThe string to replace the first found substring with. Строка, на которую будет заменена первая найденная подстрока.
    case_sensitive1BOOLEANtrueWhether the first search is case-sensitive. Учитывать ли регистр при первом поиске.
    whole_word1BOOLEANfalseWhether the first search matches whole words only. Соответствует ли первому поиску только целые слова.
    find2STRINGThe substring to find for the second replacement. Подстрока, которую нужно найти для второй замены.
    replace2STRINGThe string to replace the second found substring with. Строка, на которую будет заменена вторая найденная подстрока.
    case_sensitive2BOOLEANtrueWhether the second search is case-sensitive. Учитывать ли регистр при втором поиске.
    whole_word2BOOLEANfalseWhether the second search matches whole words only. Соответствует ли второму поиску только целые слова.
    find3STRINGThe substring to find for the third replacement. Подстрока, которую нужно найти для третьей замены.
    replace3STRINGThe string to replace the third found substring with. Строка, на которую будет заменена третья найденная подстрока.
    case_sensitive3BOOLEANtrueWhether the third search is case-sensitive. Учитывать ли регистр при третьем поиске.
    whole_word3BOOLEANfalseWhether the third search matches whole words only. Соответствует ли третьему поиску только целые слова.

    Outputs (1)

    NameTypeDescription
    STRINGSTRING