ComfyUI Node Runs on cloud

Search In Text

Check whether text contains a pattern, and count it

By Derfuu·Created 3 years ago·Updated 2 years ago· 455
Search In Text
    • BOOLEAN
    • OCCURRENCES
    Text
    Pattern
    ConsiderRegisterfalse
    Mode

    Looks for a pattern inside a string and tells you two things: whether it's there at all, and how many times it appears. It's the "does my prompt contain X?" node. On its own that sounds academic, but paired with a logic node it becomes a real tool - you can make a workflow behave differently depending on what's in the prompt text.

    It's a "String Operations" node in Derfuu_ComfyUI_ModdedNodes, the utility pack for doing programmatic things to values as they move through the graph.

    How it works

    • Text (STRING) - the text to search in.
    • Pattern (STRING) - what you're looking for.
    • ConsiderRegister (BOOLEAN, default false) - case sensitivity. "Register" is the author's term for letter case; off means the search ignores upper/lower case, on means it's exact.
    • Mode - Strict (plain substring match) or RegEx (treat the pattern as a regular expression).

    Two outputs:

    • BOOLEAN - true if the pattern was found.
    • OCCURRENCES (INT) - how many times it matched.

    Where you'd use it

    The natural pairing is with a logic node. Run your prompt through here, take the BOOLEAN, and feed it into DF_Logic_node to switch behavior - e.g. route to a different sampler or add a LoRA only when a trigger word is present. The OCCURRENCES count is handy when "how many" matters, not just "whether." And RegEx mode lets you match patterns rather than one fixed string, which is genuinely powerful if you know regular expressions - match any of several trigger words in one go.

    It composes with the rest of the string tools: assemble text with String Concatenate, then test the result here.

    Common issues & troubleshooting

    It's matching regardless of case (or not). That's the ConsiderRegister toggle. Off = case-insensitive, on = exact case. Flip it to get the behavior you want.

    My RegEx doesn't match anything. In RegEx mode the pattern is a real regular expression, so special characters (., *, (, [, etc.) have meaning. If you want to match a literal dot or parenthesis, escape it - or switch to Strict mode for a plain substring search where nothing is special.

    Count is higher than expected. Overlapping or repeated matches add up; a short pattern can hit many times inside a long prompt. Check whether you meant "contains" (use the BOOLEAN) rather than "how many" (OCCURRENCES).

    Node red / missing after a pack update. Derfuu has a history of removing old node classes on reorganizations rather than deprecating them, so updates can break saved graphs. Update via Manager and re-add the node.

    Install: ComfyUI Manager → search "Derfuu" → install → restart, or cd ComfyUI/custom_nodes && git clone https://github.com/Derfuu/Derfuu_ComfyUI_ModdedNodes then restart. No models, no heavy dependencies - pure Python.

    CategoryDerfuu_Nodes/Functions/String Operations

    Inputs (4)

    NameTypeDefaultDescription
    TextSTRING
    PatternSTRING
    ConsiderRegisterBOOLEANfalse
    ModeCOMBO2 options: Strict, RegEx

    Outputs (2)

    NameTypeDescription
    BOOLEANBOOLEAN
    OCCURRENCESINT