Nodes/ComfyUI-DataSet/DataSet_FindAndReplace
ComfyUI Node

DataSet_FindAndReplace

Find-and-Replace Across Every Caption, in One Shot

By daxcay·Created 2 years ago·Updated about a year ago· 58
DataSet_FindAndReplace
    • TextFileContents
    ◄TextFileContents—►
    â—„SearchForconceptâ–º
    â—„ReplaceWithconceptâ–º

    Every caption in your dataset says "masterpiece, best quality" and you've decided it doesn't. Or a mistyped tag is baked into all 400 files. DataSet_FindAndReplace is the batch search-and-replace for caption text - feed it your caption list, tell it what to find and what to swap in, and it hands back the whole edited list ready to be saved.

    It's the boring, obvious tool, and that's the point. It sits in the middle of the pack's caption pipeline (DataSet_TextFilesLoad → edit → DataSet_TextFilesSave) and it's the node you'll reach for when ConceptManager's position logic is more than you need and you just want a straight text swap.

    Inputs and output

    • TextFileContents - the caption list, wired in from a loader (it's forceInput, so no typing it as a widget).
    • SearchFor - the exact text to find. Multiline supported.
    • ReplaceWith - the replacement. Also multiline, and an empty string is a valid "delete this" value.

    Output is TextFileContents, the edited list. Straightforward.

    How it actually works - and where it bites

    Under the hood it's a literal Python str.replace() per caption, no regex, no case-folding. That's both the charm and the trap:

    • It's literal. Searching for cat will not match Cat. If you need case-insensitive replacement, do it in two passes.
    • It's regex-free. If you type \d+ expecting digits, you'll search for the literal backslash-d-plus. For regex work you want a different tool.
    • It replaces every occurrence in each caption, not just the first. Usually that's what you want; just know it's the behavior.

    None of that is a bug - it's replace() doing its job. But knowing it saves you a confusing debugging session.

    Install and usage

    It ships in ComfyUI-DataSet:

    cd ComfyUI/custom_nodes
    git clone https://github.com/daxcay/ComfyUI-DataSet.git
    cd ComfyUI-DataSet && pip install -r requirements.txt
    

    Restart ComfyUI afterward. No models, no network calls, pure string work.

    The one honest caveat is that there's no preview - the output is a list you can't easily eyeball on screen. If you're doing something surgical, test the replacement on a single caption first (run one file through the load node), then unleash it on the whole folder. The pack's DataSet_Visualizer can also give you a quick before/after look at your token frequencies if you want to confirm a replacement actually changed the distribution. Batch edits that touch every file deserve a dry run before you commit to disk.

    Category🔶DATASET🔶

    Inputs (3)

    NameTypeDefaultDescription
    TextFileContentsSTRING—
    SearchForSTRINGconcept—
    ReplaceWithSTRINGconcept—

    Outputs (1)

    NameTypeDescription
    TextFileContentsSTRING—