Nodes/LF Nodes/String replace
ComfyUI Node

String replace

Find-and-replace for your prompt text, no regex required

By lucafoscili·Created 2 years ago·Updated 2 years ago· 50
String replace
  • ui_widget
  • string
  • string_list
input_text
target
replacement

Text manipulation in ComfyUI is mostly string-append and string-concat - fine for building, bad for fixing. LF_StringReplace is the find-and-replace node: give it input_text, a target substring, and a replacement, and it swaps every occurrence of the target and hands back the result. Plain text, no regex, no flags to configure. It's the kind of node that looks trivial and turns out to be the missing link in a dozen small workflows.

Three inputs, and the logic is exactly what you'd type in a text editor: input_text is where replacements happen, target is the substring to find, replacement is what replaces it. The output is the rewritten string, plus a string_list variant for when you need the text as a list. It's categorized under Logic because that's how it tends to get used - as the pre-processing step that reshapes text before it reaches a downstream node.

Where it earns its place in practice:

  • Prompt cleanup. You've got a prompt with a token you want swapped across a batch - replace "night" with "dusk", or swap a character name without rebuilding the whole prompt.
  • Fixing tag syntax. Prompts from other tools come in with <lora:...> or (weight:1.2) syntaxes; a targeted replace normalizes them before they hit a text encoder or a LoRA-tag parser.
  • Data plumbing. Replace delimiters in a loaded file, strip a prefix off a set of names, or turn one format into another before it reaches a JSON or filename node.

The honest limitations: it's literal substring matching, so there's no regex, no case-insensitivity toggle, and no "only the first occurrence" option - every match gets replaced. If you need case-aware or regex-powered replacement, you're in the territory of the eval-style nodes from other packs; this one is deliberately the simple, predictable version. And note that if target appears nowhere, the text passes through unchanged - harmless, but easy to misread as "the node did nothing" if you expected a match that isn't there.

A subtle thing worth knowing: because the replacement is global (all occurrences), chaining two of these nodes is a legit pattern for multi-token cleanup - replace A→B, then C→D, and you've built a mini text pipeline out of boring parts. That's the LF philosophy in a nutshell: unglamorous nodes that compose.

Install is the pack standard: ComfyUI Manager → "LF Nodes", or git clone https://github.com/lucafoscili/comfyui-lf into custom_nodes, then restart. And the note that follows this whole pack: comfyui-lf is legacy/frozen (fully functional), with active development in lucafoscili/lf-nodes.

Category✨ LF Nodes/Logic

Inputs (4)

NameTypeDefaultDescription
input_textSTRINGThe text where replacements will occur.
targetSTRINGThe substring to be replaced.
replacementSTRINGThe substring to replace the target with.
ui_widgetoptKUL_CODE[object Object]

Outputs (2)

NameTypeDescription
stringSTRING
string_listSTRING