Text Replace
Find and replace without the regex headache
- text
TextReplace is the find-and-replace you already know how to use: plain string matching, no regex required. The wwdm-aicd pack makes a point of offering both - TxtReg's replace mode for when you need pattern power, this node for when you just want to swap "World" for "ComfyUI" and move on. Most text cleaning is the second kind.
The inputs are text, old_string, new_string, and count. count is the one to understand before you use it: 0 means "replace all," and any positive number limits how many replacements happen. "a-b-c-d" with old: "-", new: "+", count: 2 gives you "a+b+c-d". There's also an ignore_case toggle, and that's where the implementation gets interesting. Without it, the node uses plain Python str.replace. With it, it secretly switches to regex under the hood - re.sub(re.escape(old_string), new_string, ...) with the IGNORECASE flag - which means case-insensitive replacement works correctly and treats your old_string as a literal (it's escaped), so you don't have to worry about regex metacharacters biting you. That's a thoughtful detail: case-insensitive literal replace is genuinely hard to do with plain str.replace, and this just does it.
Output is a single STRING. The edge cases are friendly: if old_string is empty, it returns the text unchanged (Python's str.replace would do weird things inserting between every character, so skipping it is the right call). If old_string isn't found, nothing changes - no error, just the same text back. That's convenient until it isn't; if your replacement silently didn't happen, the old string probably isn't in the text, and a quick TextSearch contains check will tell you.
Install is the pack's usual no-fuss story:
cd ComfyUI/custom_nodes
git clone https://github.com/wwsmiao/comfyui-wwdm-aicd.git
Restart ComfyUI, look under wwdm-aicd. Stdlib only - no requirements.txt exists in the repo despite what the README's install block implies. README and source comments are in Chinese; widgets are English.
Real uses: the README's cleaning chain (TextTrim → TextReplace → TextCase → TextLength) for normalizing punctuation, swapping a brand name in a generated prompt, or stripping a recurring token out of LLM output. If your cleanup needs patterns - "replace every number," "swap anything in parentheses" - that's TxtReg's replace mode with replacement and groups, and this node will feel underpowered. But for the 80% of replacements that are exact-string swaps, it's simpler, more predictable, and you'll reach for it first.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| old_string | STRING | — | |
| new_string | STRING | — | |
| count | INT | 0 | — |
| ignore_caseopt | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |