SVG String Replace
The blunt instrument that saves you 90% of SVG cleanup time
- STRING
Sometimes you don't need a parser, a selector engine, or any cleverness at all. You need to find every #FF0000 in the file and make it #00FF00, or strip a mangled namespace prefix that's showing up everywhere. SVG String Replace is find-and-replace for your SVG text, full stop. It's the most basic node in this pack and genuinely one of the most useful - because most SVG editing problems are, at the end of the day, string problems.
How it works
You give it an svg_string, a find_pattern, and a replace_with, and it does a plain text replacement. Three modifiers:
- case_sensitive (default
true) - flip off to catchfillandFillandFILLin one pass. - use_regex (default
false) - turn the pattern into a regular expression. This is where it becomes a power tool:fill="(#[0-9a-fA-F]{6})"can match every hex fill in one expression. Regex is the difference between "this node is a toy" and "this node replaces half the pack." - limit_replacements (default 0 = unlimited) - cap how many matches get swapped, for when the first occurrence is special and the rest aren't.
If find_pattern is empty, it returns the SVG untouched. Output is a single STRING - the modified markup.
Why you'd reach for it instead of the "smart" nodes
The color nodes are exact-match on hex and touch specific attributes; this node replaces whatever text you say, wherever it appears. That's the feature and the danger in one. A global replace of fill as a bare word would clobber fill-opacity too, and #FF0000 in a comment would get changed just as happily as in a path. No structure awareness, no safety rails.
But that bluntness is exactly the win in the messy cases: a vendor SVG with a broken prefix repeated 400 times, or a color stored as rgb(255, 0, 0) that the color nodes won't touch. This node fixes those, and regex makes it surgical enough to do so safely.
Install
Pack standard:
cd ComfyUI/custom_nodes
git clone https://github.com/MushroomFleet/svg-suite
pip install -r requirements.txt
Restart ComfyUI, or via Manager under "svg-suite". Pure string ops - zero dependencies beyond Python itself, so it works even if the tracing stack failed to install.
Where people get burned
Regex mistakes. A bad expression can silently mangle your SVG (or, with an empty replace_with, delete big chunks of it). There's no undo and no preview inside the node - preview via SVG Preview (Advanced) or eyeball the output before you trust it.
Also: this node does not respect SVG structure. If you need "only inside fill attributes" or "only the first element," use SVG Color Replacer or SVG Attribute Manipulation instead. And remember text replacement hits comments and strings too, so if your SVG embeds XML-escaped content, your replacement may fire somewhere you didn't intend. For everything else - and there's a lot - this is the fastest tool in the box.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| svg_string | STRING | — | |
| find_pattern | STRING | — | |
| replace_with | STRING | — | |
| case_sensitive | BOOLEAN | true | — |
| use_regex | BOOLEAN | false | — |
| limit_replacementsopt | INT | 00–1000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |