AGSoft Text Replace
Find-and-replace for prompts, with up to three swaps in one pass
- STRING
"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
findstrings arere.escaped, so special characters like.,*, or(are treated literally - no regex surprises unless you intentionally use the features below. case_sensitivetogglesre.IGNORECASE(default on, so it behaves like a plain search).whole_wordwraps the pattern in\bword boundaries, sofind="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 qualitywithmasterpiece, 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.
Inputs (13)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | The original text in which to perform replacements. Исходный текст, в котором будут выполняться замены. | |
| find1 | STRING | The substring to find for the first replacement. Подстрока, которую нужно найти для первой замены. | |
| replace1 | STRING | The string to replace the first found substring with. Строка, на которую будет заменена первая найденная подстрока. | |
| case_sensitive1 | BOOLEAN | true | Whether the first search is case-sensitive. Учитывать ли регистр при первом поиске. |
| whole_word1 | BOOLEAN | false | Whether the first search matches whole words only. Соответствует ли первому поиску только целые слова. |
| find2 | STRING | The substring to find for the second replacement. Подстрока, которую нужно найти для второй замены. | |
| replace2 | STRING | The string to replace the second found substring with. Строка, на которую будет заменена вторая найденная подстрока. | |
| case_sensitive2 | BOOLEAN | true | Whether the second search is case-sensitive. Учитывать ли регистр при втором поиске. |
| whole_word2 | BOOLEAN | false | Whether the second search matches whole words only. Соответствует ли второму поиску только целые слова. |
| find3 | STRING | The substring to find for the third replacement. Подстрока, которую нужно найти для третьей замены. | |
| replace3 | STRING | The string to replace the third found substring with. Строка, на которую будет заменена третья найденная подстрока. | |
| case_sensitive3 | BOOLEAN | true | Whether the third search is case-sensitive. Учитывать ли регистр при третьем поиске. |
| whole_word3 | BOOLEAN | false | Whether the third search matches whole words only. Соответствует ли третьему поиску только целые слова. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |