LogicUtil_Replace String
Regex replace — read the fine print before you wire it up
- STRING
LogicUtil_Replace String does text replacement in the graph, but with a critical detail hidden in the fine print: the "find" field is a regular expression, not a plain text search. Three inputs - String, Regex, and ReplaceWith - and one STRING out, produced by Python's re.sub(Regex, ReplaceWith, String). If you treat Regex like a plain "find this exact text" field, you will be confused within minutes.
How it works
That regex behavior is the whole story. It means the node is genuinely powerful and genuinely easy to misuse:
- Want to strip all digits from a prompt?
Regex = \d+- gone. - Want to swap
portraitforlandscape? That works as plain text too, as long as you remember regex metacharacters. Search fora.band it'll matchacbas well asa.b, because.is a wildcard. - Empty
Regexis a trap.re.sub('', X, text)insertsReplaceWithbetween every character. SetRegexto empty and your string comes back with the replacement sprinkled throughout. It won't error - it'll just look wrecked. - Need to match a literal
$or(? Escape it:\$,\(. This is the single most common cause of "replace did nothing" - the metacharacter matched something you didn't see.
There's no case-insensitivity flag and no "replace all vs first" toggle - re.sub always replaces every match, case-sensitively. If you need case-insensitive matching, include (?i) at the start of your pattern.
Where you'd actually use it: cleaning scraped or imported prompts, normalizing filenames before they hit a saver node, or building a prompt-rewriter that strips one style token and injects another. It plays well with the rest of the family - Manual Choice String for options, Replace String for rewriting, Merge String for assembly. The whole family is a port of aria1th's ComfyUI-LogicUtils riding inside the JDCN pack from Daxton Caylor and Jerry Davos; the README documents the file and latent batch nodes and never mentions this one, so the source is the doc - and the source is unambiguously regex.
Install
Install is the standard JDCN routine: ComfyUI Manager → "Install Custom Node" → search JDCN → install → restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/daxcay/ComfyUI-JDCN
cd ComfyUI-JDCN && pip install -r requirements.txt
Only piexif on the requirements list, no models to fetch. And the fastest sanity check when a replacement looks wrong: put a literal, non-meta string in Regex and confirm it works, then add metacharacters back one at a time.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| String | STRING | — | |
| Regex | STRING | — | |
| ReplaceWith | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |