Nodes/ComfyUI-Light-Tool/Light-Tool: Text Replace
ComfyUI Node

Light-Tool: Text Replace

Find-and-replace for your prompts — regex included

By ihmily·Created 2 years ago·Updated 4 months ago· 20
Light-Tool: Text Replace
    • text
    text
    search
    replace
    use_regexfalse
    case_sensitivetrue

    Light-Tool: TextReplace is a find-and-replace node for text - mostly prompts - with a regex mode bolted on for when simple matching won't cut it. Feed it a string, tell it what to search for and what to swap in, and it returns the edited text. It's the kind of tiny utility that becomes a habit once you realize how much prompt-building is just string surgery.

    The killer use case is dynamic prompt manipulation. "This workflow always says photorealistic portrait but this week I want oil painting portrait" - wire the search and replace fields to widgets, and the whole graph's text changes from one panel. Same for swapping model-style triggers, cleaning up malformed text from a LoRA stack, or normalizing output before it hits a text-display node.

    How it works

    Two matching modes, chosen by use_regex:

    • Off (default) - plain substring replace. search gets replaced everywhere it appears in text. If search is empty, the text passes through untouched.
    • On - search is treated as a regular expression. The node finds every match and replaces each one. Invalid patterns raise a clear ValueError instead of silently misbehaving.

    There's also case_sensitive (default on). Turn it off and matching becomes case-insensitive in both modes - handy for prompt text where capitalization is inconsistent.

    One implementation detail worth knowing: in regex mode the node first finds all matches with re.findall, then replaces them. It's fine for the normal case, but be aware that your replacement is applied per matched string, not with regex backreference semantics - if you're planning \1-style group substitution, this node won't do that, and you'd want a more full-featured text node.

    Inputs and output

    • text - the multiline input to process.
    • search - what to find (plain or regex).
    • replace - the replacement text.
    • use_regex, case_sensitive - the toggles above.

    Output is a single text string. Keep in mind it operates on one string at a time - for lists of strings, feed each item or check whether your downstream accepts the list directly.

    The honest take

    Simple replacement is trivial to do by hand, but the value here is that it's inside the graph and driven by inputs. You can chain two of these to build a poor-man's prompt template engine: first swap a style token, then clean up the result. It won't replace a real templating pack, but for the majority of "I just need this one phrase swapped everywhere," it's the least ceremony in town.

    Install

    Standard: ComfyUI Manager → search ComfyUI-Light-Tool, or clone into custom_nodes, pip install -r requirements.txt, restart. It lives under ComfyUI-Light-Tool → Text. No models, no external services.

    CategoryComfyUI-Light-Tool/Text

    Inputs (5)

    NameTypeDefaultDescription
    textSTRING
    searchSTRING
    replaceSTRING
    use_regexBOOLEANfalse
    case_sensitiveBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    textSTRING