Nodes/ComfyUI-mnemic-nodes/🧹 String Cleaning
ComfyUI Node

🧹 String Cleaning

String Cleaning β€” ComfyUI Node Guide

By MNeMoNiCuZΒ·Created 3 years agoΒ·Updated 16 days agoΒ· 105
🧹 String Cleaning
    • cleaned_string
    β—„input_stringβ€”β–Ί
    β—„collapse_sequential_spacesfalseβ–Ί
    β—„strip_leading_spacesfalseβ–Ί
    β—„strip_trailing_spacesfalseβ–Ί
    β—„strip_empty_linesfalseβ–Ί
    β—„strip_leading_symbolsfalseβ–Ί
    β—„strip_trailing_symbolsfalseβ–Ί
    β—„strip_newlinesfalseβ–Ί
    β—„replace_newlines_with_period_spacefalseβ–Ί
    β—„strip_inside_tagsβ–Ί
    β—„strip_between_startβ–Ί
    β—„strip_between_endβ–Ί
    β—„strip_leading_customβ–Ί
    β—„strip_trailing_customβ–Ί
    β—„strip_all_customβ–Ί
    β—„remove_text_beforeβ–Ί
    β—„remove_text_afterβ–Ί
    β—„multiline_findβ–Ί
    β—„multiline_replaceβ–Ί

    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.

    Category⚑ MNeMiC Nodes

    Inputs (19)

    NameTypeDefaultDescription
    input_stringSTRINGEnter the text to be cleaned.
    collapse_sequential_spacesBOOLEANfalseReplace multiple spaces with a single space.
    strip_leading_spacesBOOLEANfalseStrip leading spaces from each line in the text.
    strip_trailing_spacesBOOLEANfalseStrip trailing spaces from each line in the text.
    strip_empty_linesBOOLEANfalseRemove empty or whitespace-only lines from the text.
    strip_leading_symbolsBOOLEANfalseStrip leading punctuation symbols (, . ! ? : ;) from each line.
    strip_trailing_symbolsBOOLEANfalseStrip trailing punctuation symbols (, . ! ? : ;) from each line.
    strip_newlinesBOOLEANfalseRemove all newlines from the text.
    replace_newlines_with_period_spaceBOOLEANfalseReplace one or multiple newlines with a period followed by a space.
    strip_inside_tagsSTRINGEnter pairs of characters to strip content between them (one pair per line). Example Input: () [] {} Input: 'Hello (world) and [text]' Output: 'Hello and'
    strip_between_startSTRINGEnter 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_endSTRINGEnter end tags to strip content to (one per line). Must match number of Start Tags lines. Example: '</think>'
    strip_leading_customSTRINGEnter 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_customSTRINGEnter custom strings to strip from the end of each line. Example Input: 'END' Input: 'Hello END World END' Output: 'Hello World'
    strip_all_customSTRINGEnter custom strings to remove throughout the text. Example Input: 'the' Input: 'the cat and the dog' Output: 'cat and dog'
    remove_text_beforeSTRINGEnter markers to find. All text before (and including) these markers will be removed. Example: '<START>' Input: 'Header <START> Content' Output: ' Content'
    remove_text_afterSTRINGEnter markers to find. All text after (and including) these markers will be removed. Example: '<END>' Input: 'Content <END> Footer' Output: 'Content '
    multiline_findSTRINGEnter strings to find (one per line). Example: 'old' to be replaced with 'new' Must match number of Replace Strings lines
    multiline_replaceSTRINGEnter replacement strings (one per line). Example: 'new' to replace 'old' Must match number of Find Strings lines

    Outputs (1)

    NameTypeDescription
    cleaned_stringSTRINGThe string after all the selected cleaning operations have been applied.