π§Ή String Cleaning
String Cleaning β ComfyUI Node Guide
- cleaned_string
Text coming out of anywhere automated - an LLM response, a scraped caption, a metadata field - is rarely clean enough to use as-is, and this node is a single stop for the whole category of "strip this junk out" problems rather than a one-trick fixer. It's a long list of toggles and text-pair fields, almost all off by default, so nothing happens to your text unless you deliberately switch something on.
The everyday case is the simplest one: collapse_sequential_spaces, strip_leading_spaces, strip_trailing_spaces, and strip_empty_lines cover the "my text came back with sloppy whitespace" problem that shows up constantly after copy-pasting or parsing something automated. Turn on whichever combination matches what you're seeing.
The most practically useful trick in here, though, is strip_between_start / strip_between_end, and it's worth calling out specifically because the tooltip's own example is exactly the situation you'll hit if you're running this pack's Groq LLM API node against a reasoning model: set the start tag to <think> and the end tag to </think>, and the node removes an entire chain-of-thought block - everything between those two markers - leaving just the actual answer. Reasoning models routinely emit their internal deliberation wrapped in tags like that before the real response, and if you're feeding that response straight into a prompt or a save file without cleaning it first, you're shipping the model's scratch work along with it. The same pair-based pattern (strip_inside_tags for symmetric pairs like (), [], {}; remove_text_before / remove_text_after for one-sided markers) covers related cases - stripping parenthetical asides, or cutting everything before/after a specific delimiter in structured text.
Beyond those, there's a longer tail of narrower tools for less common situations: strip_leading_symbols / strip_trailing_symbols for stray punctuation at line edges, strip_newlines and replace_newlines_with_period_space for collapsing multi-line text into one flowing line, strip_leading_custom / strip_trailing_custom / strip_all_custom for removing your own specific strings (a repeated "Chapter" prefix, a boilerplate suffix), and multiline_find / multiline_replace as a manual find-and-replace pair, matched line by line.
Output: a single cleaned_string, and because this is an output node it shows the result directly in the UI too - genuinely handy for iterating on which toggles you actually need without wiring a separate Preview Text node.
Installing it: ComfyUI Manager, search "ComfyUI-mnemic-nodes," or git clone https://github.com/MNeMoNiCuZ/ComfyUI-mnemic-nodes into custom_nodes, then restart. It's string processing, nothing more - no dependencies to fight with.
Two real gotchas, both stated directly in the tooltips: multiline_find and multiline_replace are matched by line position, so they must have the same number of lines or the pairing breaks - the same requirement applies to strip_between_start and strip_between_end, which must line up one-to-one. And because every toggle defaults to off, the most common confusion is plugging text in, getting the exact same text back, and assuming the node is broken - check that you've actually enabled something before troubleshooting further.
Inputs (19)
| Name | Type | Default | Description |
|---|---|---|---|
| input_string | STRING | Enter the text to be cleaned. | |
| collapse_sequential_spaces | BOOLEAN | false | Replace multiple spaces with a single space. |
| strip_leading_spaces | BOOLEAN | false | Strip leading spaces from each line in the text. |
| strip_trailing_spaces | BOOLEAN | false | Strip trailing spaces from each line in the text. |
| strip_empty_lines | BOOLEAN | false | Remove empty or whitespace-only lines from the text. |
| strip_leading_symbols | BOOLEAN | false | Strip leading punctuation symbols (, . ! ? : ;) from each line. |
| strip_trailing_symbols | BOOLEAN | false | Strip trailing punctuation symbols (, . ! ? : ;) from each line. |
| strip_newlines | BOOLEAN | false | Remove all newlines from the text. |
| replace_newlines_with_period_space | BOOLEAN | false | Replace one or multiple newlines with a period followed by a space. |
| strip_inside_tags | STRING | Enter pairs of characters to strip content between them (one pair per line). Example Input: () [] {} Input: 'Hello (world) and [text]' Output: 'Hello and' | |
| strip_between_start | STRING | Enter start tags to strip content from (one per line). Example: '<think>' Input: '<think>Hmm, so the user has asked us to...</think> The answer is 24' Output: 'The answer is 24' | |
| strip_between_end | STRING | Enter end tags to strip content to (one per line). Must match number of Start Tags lines. Example: '</think>' | |
| strip_leading_custom | STRING | Enter custom strings to strip from the start of each line. Example Input: 'Chapter' Input: 'Chapter 1: Hello Chapter 2: World' Output: '1: Hello 2: World' | |
| strip_trailing_custom | STRING | Enter custom strings to strip from the end of each line. Example Input: 'END' Input: 'Hello END World END' Output: 'Hello World' | |
| strip_all_custom | STRING | Enter custom strings to remove throughout the text. Example Input: 'the' Input: 'the cat and the dog' Output: 'cat and dog' | |
| remove_text_before | STRING | Enter markers to find. All text before (and including) these markers will be removed. Example: '<START>' Input: 'Header <START> Content' Output: ' Content' | |
| remove_text_after | STRING | Enter markers to find. All text after (and including) these markers will be removed. Example: '<END>' Input: 'Content <END> Footer' Output: 'Content ' | |
| multiline_find | STRING | Enter strings to find (one per line). Example: 'old' to be replaced with 'new' Must match number of Replace Strings lines | |
| multiline_replace | STRING | Enter replacement strings (one per line). Example: 'new' to replace 'old' Must match number of Find Strings lines |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| cleaned_string | STRING | The string after all the selected cleaning operations have been applied. |