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

🧹 String Cleaning

Strip Think Tags, Punctuation and Stray Whitespace

By MNeMoNiCuZΒ·Created 3 years agoΒ·Updated a day 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β–Ί

    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. Chapter on 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.

    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.