π§Ή String Cleaning
Strip Think Tags, Punctuation and Stray Whitespace
- cleaned_string
If you pipe an LLM's output into a prompt box, you get LLM formatting with it: Okay, here's an enhanced prompt: on the front, a <think> block nobody asked for, markdown bullets, three line breaks, and a closing bit of encouragement. π§Ή String Cleaning is the node that flattens all of that into one usable line. It's the least glamorous node in this pack and probably the one you'll use most if you run any text-generating branch.
The <think> use case is the author's own headline example, and it's the one that bites in practice: reasoning models emit a scratchpad before the answer, you don't want the scratchpad near CLIP, and the pack's Groq LLM node feeds straight into this.
How it works
It's a stack of independent booleans plus a few find-and-replace boxes, applied to input_string as one pass. Nothing happens unless you tick something, so it's safe to leave inline.
The toggles: collapse_sequential_spaces (many spaces β one), strip_leading_spaces / strip_trailing_spaces (per line), strip_empty_lines, strip_leading_symbols / strip_trailing_symbols (leading punctuation , . ! ? : ; per line), strip_newlines, and replace_newlines_with_period_space - which turns any run of line breaks into a single . , the trick for feeding a paragraph to a tag-based model without losing the sentence boundary.
The string fields are where the real power is, and they're all one-entry-per-line:
strip_inside_tags- character pairs like()[]{}; removes the bracketed content entirely.Hello (world) and [text]βHello and.strip_between_start/strip_between_end- matched pairs, line for line.<think>β¦</think>is the canonical use, and it removes the markers along with the content. Both boxes must have the same number of lines.strip_leading_custom/strip_trailing_custom- literal strings removed from the start or end of each line.Chapteron every line, gone. A single space works too.strip_all_custom- removes the string everywhere, not just the edges.remove_text_before/remove_text_after- chop to (and including) a marker, so you can throw away a preamble or a trailing sign-off.multiline_find/multiline_replace- straight find-and-replace, processed in order.
The whole thing outputs one string. That's the trade: you can't use it as a filter chain and see the intermediate steps, so when output looks wrong, tick the boxes one at a time until you find the culprit.
Inputs and outputs
Everything above is a required input except the optional ones are absent - the schema declares them all required, so each box exists whether you use it or not. The only output is cleaned_string, a STRING, which goes into a CLIP Text Encode, a Save Text File, or a String Concat.
Install
ComfyUI Manager β search "ComfyUI-mnemic-nodes" β install β restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/MNeMoNiCuZ/ComfyUI-mnemic-nodes
No downloads, no keys. The pack's heavier dependencies belong to its other nodes.
Common issues
Content between tags survives. Check both start and end boxes have the same number of lines, in matching order. A missing counterpart doesn't strip.
Everything vanished. strip_all_custom with a common word in it, or a remove_text_after marker that appears early in the text. Untick and re-test.
The output is one long line and you wanted that. That's strip_newlines or replace_newlines_with_period_space. Use the second one for prompts - sentence breaks read better to an encoder than a run-on.
A line-break-related rule isn't applying. The custom strip fields work per line and can't remove line breaks themselves.
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. |