Nodes/ComfyUI_StringEssentials/String Contains Any
ComfyUI Node

String Contains Any

The text gate that decides which LoRA loads

By bradsec·Created 2 years ago·Updated 2 months ago· 36
String Contains Any
    • contains_any
    • matched_string
    input_string
    substrings
    match_casefalse

    This is the pack's router. String Contains Any reads a text input, checks it against a list of substrings, and returns a boolean for "did any of them show up" plus the first string that matched. In a graph where every decision is a wire, that boolean is what turns a static prompt into a branching one.

    The README's own example is the one you'll actually build: check the prompt for anime, manga, or cel-shaded - if any appear, route to an anime LoRA; otherwise keep the realistic one. Prompt says anime girl in a park? contains_any comes back true and your LoRA loader picks accordingly. That pattern generalizes to style switching, subject detection, negative-prompt cleanup decisions, and any workflow where text should make a choice.

    How it works

    Simple and predictable. The node takes substrings one per line, then does a plain substring scan over the input in the order you listed them. First hit wins and returns immediately: contains_any = true plus that matched string. If nothing hits, you get false and an empty string. match_case is off by default, so Cel-Shaded and cel-shaded match each other.

    The inputs and outputs

    • input_string (wired) - the text to search. Usually the prompt, but it'll happily search any string: an image-to-text description, a filename, an LLM reply.
    • substrings - one per line. Order matters only for which one gets reported as matched_string, since the first hit wins.
    • match_case - default off (case-insensitive).

    Outputs: contains_any (BOOLEAN) and matched_string (STRING - the winning substring, or "" if none). matched_string is the underrated half: it lets you know which branch you're on, so you can key a decision off a specific term rather than just true/false.

    Installation

    Same story as the rest of the pack: no dependencies, no model downloads, pure Python. Via ComfyUI Manager: Manager > Custom Nodes Manager > search "ComfyUI_StringEssentials" > Install, restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/bradsec/ComfyUI_StringEssentials.git
    

    Restart, then find it under Add Node > utils > StringEssentials.

    Gotchas

    • Substring matching, again. art matches artistic and part. There's no whole-word toggle here, so keep your check terms specific (cel-shaded beats shaded) or pre-tokenize upstream. This is the same limitation as String Conditional Append, and worth remembering whenever you're surprised a gate opened.
    • The boolean doesn't route anything by itself. ComfyUI has no native if-node, so contains_any needs a switch/condition node to act on - the kind that ships in utility packs like rgthree-comfy. The pattern is Contains Any → boolean → switch/LoRA loader. If you wire the boolean straight into a sampler you'll get an error, not a branch.
    • Empty substring list returns (false, "") every time, which is a silent always-false gate. If your gate seems stuck shut, check that the list actually parsed - a stray blank line at the top of the multiline box is easy to miss.
    • Case-insensitivity is the default; flip match_case on only when the distinction genuinely matters.

    For the price of one small node, your workflow learns to read its own prompt. That's a cheap upgrade.

    Categoryutils/StringEssentials

    Inputs (3)

    NameTypeDefaultDescription
    input_stringSTRINGThe string to search within
    substringsSTRINGEnter substrings to check (one per line). Returns true if ANY are found.
    match_caseBOOLEANfalseWhether the search should be case-sensitive

    Outputs (2)

    NameTypeDescription
    contains_anyBOOLEAN
    matched_stringSTRING