Nodes/comfyui-OreX/✍️ String Function (OreX)
ComfyUI Node

✍️ String Function (OreX)

A mini template engine for string manipulation

By orex2121·Created about a year ago·Updated 3 days ago· 34
✍️ String Function (OreX)
  • A
  • B
  • C
  • D
  • string
string_function

ComfyUI's string handling is famously bare-bones - there's text in, text out, and not a lot of "do something to it." String Function (OreX) is the pack's answer: a tiny template engine where you write a pattern in the string_function box and it pulls values from up to four any-typed inputs (A, B, C, D) into placeholders, with optional find-and-replace chains. It's the kind of node you don't need until you need it, and then you need it three times in one workflow.

How it works

You write a template using {A}, {B}, {C}, {D} as placeholders - any string, number, or even tensor-connected value (inputs are any_type, so ComfyUI won't fight you on types) gets stringified and dropped in. On top of that, each placeholder can carry a replacement chain:

{A(hello->goodbye)(  ->_)} {B}

The (old->new) pairs run as sequential str.replace operations on the substituted value - so {A(hello->goodbye)} inserts A's value with "hello" changed to "goodbye". The old and new strings can themselves reference other variables ({A(hello->{B})} swaps in B's value), which is how you build substitutions that depend on more than one input. Empty replacements ((hello->)) delete text; an unconnected input becomes an empty string and its whole placeholder vanishes rather than leaving a {A} corpse in the output.

The result is deterministic string manipulation: character substitutions, cleanup patterns, reformatting - all inside one node instead of chained string-utility nodes. Output is a single string.

What you'd actually use it for

  • Prompt cleanup - strip trailing commas or double spaces from a generated prompt before it hits the text encoder.
  • Name formatting - turn a raw filename into a labeled string.
  • Composition - build a filename or label from several values (batch label + index + suffix) for downstream Save Text/Save Image nodes.
  • Sanitization - replace characters that break a file system or a model's tokenizer.

Install

ComfyUI Manager (search "comfyui-OreX") or:

cd ComfyUI/custom_nodes
git clone https://github.com/orex2121/comfyui-OreX

Restart. Pure Python regex, zero dependencies.

The honest caveat

The syntax has a learning curve - the (old->new) chains are clever but terse, and a typo in the pattern silently produces a wrong string instead of an error. Test your pattern with a Preview Text node before wiring it into something load-bearing. It also won't do math or logic; it's text replacement only. But for the "turn these three values into this one string" problem, it beats a pile of concatenation nodes hands down.

CategoryOreX

Inputs (5)

NameTypeDefaultDescription
string_functionSTRING
Aopt*
Bopt*
Copt*
Dopt*

Outputs (1)

NameTypeDescription
stringSTRING