Nodes/WAS Node Suite v3/Text Find and Replace
ComfyUI Node Runs on cloud

Text Find and Replace

Swap a substring in your prompt mid-graph

By WASasquatch·Created 3 years ago·Updated 5 days ago· 1,844
Text Find and Replace
  • find
  • replace
  • find_2
  • replace_2
  • find_3
  • replace_3
  • find_4
  • replace_4
  • find_5
  • replace_5
  • find_6
  • replace_6
  • find_7
  • replace_7
  • find_8
  • replace_8
  • result_text
  • replacement_count_number
  • replacement_count_float
  • replacement_count_int
text

Exactly what it says: it finds a substring in your text and replaces it with something else. Text Find and Replace is the search-and-replace you already know from every text editor, dropped into the ComfyUI graph so you can rewrite prompt text on the fly.

Where it earns its place is templating. Keep a base prompt with a placeholder - a photo of SUBJECT in a forest - and swap SUBJECT for whatever you're generating this run. Combine it with the batch text nodes and you've got a poor man's prompt template engine: one skeleton, many fillings, without retyping the whole prompt each time.

How it works

The README description is the whole node: "Find and replace a substring in a string." You give it the input text, the substring to find, and the replacement, and it returns the text with every match swapped. Straightforward string replacement - feed a prompt in, get the edited prompt out.

It shines in a chain. Load a base prompt from a Text Multiline or a file, run it through Find and Replace to inject the variable part, then concatenate on your quality tags and encode. Each transformation is a visible node instead of manual editing, which means you can wire the replacement value from somewhere else in the graph and let it change automatically.

Inputs and outputs that matter

The three inputs that matter are the text to operate on, the find substring (what to look for), and the replace substring (what to put there). The output is the rewritten STRING, which flows into a CLIP encode, this pack's Text to Conditioning, or another text node for more processing.

Note the WAS text convention: outputs are plain STRING now, not the legacy ASCII type. If an old guide references ASCII text, it's the same wire renamed for clarity in 2023.

How to install it

ComfyUI Manager: search was-node-suite-comfyui, install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui

then install the pack's requirements.txt in your ComfyUI venv and restart. Pure string handling - no downloads.

Common issues & troubleshooting

Nothing got replaced. The find string has to match exactly, and it's typically case-sensitive - Subject won't match subject. Check spelling, capitalization, and any stray spaces in your placeholder. A placeholder that's easy to type unambiguously (like __SUBJECT__) avoids accidental partial matches.

It replaced too much. Substring replace matches anywhere the text appears, including inside other words. If your find token is a common fragment, it'll hit unintended spots. Use a distinctive placeholder that can't occur naturally in your prompt.

I need multiple replacements at once. This node does one find/replace. For several swaps, chain a few of these, or look at the pack's "Text Find and Replace by Dictionary," which applies a whole dictionary of replacements in one node.

I wanted regex / pattern matching. This is a plain substring swap, not a full regex engine. For simple placeholder filling it's perfect; for pattern-based edits you'll want something more specialized.

Whole pack won't import after a ComfyUI update. The familiar WAS Node Suite issue - package downgrades vs a ComfyUI bump. Re-run the pack's requirements against the activated venv, or install.bat. Maintenance-only since late 2023.

CategoryWAS Suite/Text/Search

Inputs (17)

NameTypeDefaultDescription
textSTRINGText to search; STRING, as `a tabby cat`. Every filled find box is applied in one pass over it.
findSTRING,ARRAYA regular expression, so 'cat|dog' matches either word and '\s+' matches whitespace. A backslash makes a special character literal. Left empty, nothing is replaced.
replaceSTRING,ARRAYWhat each match becomes. Leave it empty to delete the matches. \1 and \2 stand for the first and second parenthesised group of the pattern, and a literal backslash has to be doubled.
find_2optSTRING,ARRAYAnother pattern, searched in the same single pass as the first. Every pattern is tried against the text as it arrived, so a replacement is never matched again by a later pattern and two patterns can swap. Where two patterns match at the same place, the earlier box wins.
replace_2optSTRING,ARRAYWhat the pattern in the box above becomes. Leave it empty to delete what that pattern matched, the same as the first pair.
find_3optSTRING,ARRAYAnother pattern, searched in the same single pass as the first. Every pattern is tried against the text as it arrived, so a replacement is never matched again by a later pattern and two patterns can swap. Where two patterns match at the same place, the earlier box wins.
replace_3optSTRING,ARRAYWhat the pattern in the box above becomes. Leave it empty to delete what that pattern matched, the same as the first pair.
find_4optSTRING,ARRAYAnother pattern, searched in the same single pass as the first. Every pattern is tried against the text as it arrived, so a replacement is never matched again by a later pattern and two patterns can swap. Where two patterns match at the same place, the earlier box wins.
replace_4optSTRING,ARRAYWhat the pattern in the box above becomes. Leave it empty to delete what that pattern matched, the same as the first pair.
find_5optSTRING,ARRAYAnother pattern, searched in the same single pass as the first. Every pattern is tried against the text as it arrived, so a replacement is never matched again by a later pattern and two patterns can swap. Where two patterns match at the same place, the earlier box wins.
replace_5optSTRING,ARRAYWhat the pattern in the box above becomes. Leave it empty to delete what that pattern matched, the same as the first pair.
find_6optSTRING,ARRAYAnother pattern, searched in the same single pass as the first. Every pattern is tried against the text as it arrived, so a replacement is never matched again by a later pattern and two patterns can swap. Where two patterns match at the same place, the earlier box wins.
replace_6optSTRING,ARRAYWhat the pattern in the box above becomes. Leave it empty to delete what that pattern matched, the same as the first pair.
find_7optSTRING,ARRAYAnother pattern, searched in the same single pass as the first. Every pattern is tried against the text as it arrived, so a replacement is never matched again by a later pattern and two patterns can swap. Where two patterns match at the same place, the earlier box wins.
replace_7optSTRING,ARRAYWhat the pattern in the box above becomes. Leave it empty to delete what that pattern matched, the same as the first pair.
find_8optSTRING,ARRAYAnother pattern, searched in the same single pass as the first. Every pattern is tried against the text as it arrived, so a replacement is never matched again by a later pattern and two patterns can swap. Where two patterns match at the same place, the earlier box wins.
replace_8optSTRING,ARRAYWhat the pattern in the box above becomes. Leave it empty to delete what that pattern matched, the same as the first pair.

Outputs (4)

NameTypeDescription
result_textSTRINGThe text with every match replaced.
replacement_count_numberNUMBERHow many replacements were made, for the NUMBER inputs of the suite's own maths and logic nodes. 0 means the text was not matched at all.
replacement_count_floatFLOATThe same count as a decimal, for example 3.0.
replacement_count_intINTThe same count as a whole number, for a core INT input.