Regex replace
Find-and-replace for prompts, using real Python regex
- ui_widget
- string
- string_list
Sometimes you don't need a smart parsing node, you just need to find a pattern in a string and swap it for something else - strip out leftover LoRA tags after using a different LoRA-tag node, normalize double spaces, cut a trailing comma, whatever. LF_RegexReplace is that: a plain regex find-and-replace, no frills, doing exactly what re.sub does in Python because that's literally what's running under the hood - the flags option names IGNORECASE, MULTILINE, and DOTALL, which are Python's own regex flag names, not some custom dialect.
Three required inputs: input_text is what you're searching through, pattern is the regex to match, replacement is what matches get swapped for. flags is optional and takes a comma-separated list of flag names if you need case-insensitive matching or want . to match newlines - leave it at the default 0 for plain matching. Outputs are string (the result as a single value) and string_list (the same result wrapped as a list, useful if something downstream specifically wants a list type rather than a scalar string).
There's also an optional ui_widget slot that renders a code editor on the node - that's for viewing/editing your pattern comfortably, not a separate input you wire a value into.
It's a genuinely general-purpose utility, which is both its strength and its limit - it doesn't know anything about ComfyUI prompts specifically, LoRA syntax, or any domain-specific structure. That's deliberate: a plain, predictable find-and-replace composes with everything else in your graph, whereas a "smart" prompt-aware regex node would be one more thing to learn the quirks of. If you're doing something more structured than pattern matching - pulling a delimited value out with type conversion, say - LF_ExtractString is the better fit; keep this one for the cases where a straightforward substitution is genuinely all you need.
Installing it. ComfyUI Manager: search "LF Nodes," install, restart. Manual: cd ComfyUI/custom_nodes && git clone https://github.com/lucafoscili/lf-nodes, then restart ComfyUI. Use that repo - comfy.icu's listing links comfyui-lf, which is the pack's original home, now archived after the author's migration to lf-nodes. No models or heavy dependencies to worry about; this is a text-processing node, nothing GPU-related.
Where people get tripped up. If your pattern isn't matching, the usual suspects apply: forgetting to escape special regex characters like ., (, or [ when you actually want them treated literally, or expecting case-insensitive matching by default when you need to explicitly set IGNORECASE in flags. If you're coming from a different regex flavor (JavaScript, PCRE with different syntax quirks), remember this is Python's re module - mostly compatible, but named groups and a few escape sequences differ slightly, so test tricky patterns in a Python shell first if something behaves unexpectedly. And if you want structural JSON parsing rather than pattern matching, this is the wrong tool - LF_ExtractString or LF_StringToJSON from the same pack are built for that instead.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| input_text | STRING | The text where the regex replacements will occur. | |
| pattern | STRING | The regex pattern to match. | |
| replacement | STRING | The substring to replace the regex matches with. | |
| flagsopt | STRING | 0 | Regex flags to use. Comma-separated list: IGNORECASE, MULTILINE, DOTALL, etc. |
| ui_widgetopt | KUL_CODE | [object Object] | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| string | STRING | — |
| string_list | STRING | — |