Nodes/ComfyUI-JDCN/LogicUtil_AContainsB(String)
ComfyUI Node

LogicUtil_AContainsB(String)

It's regex, not 'does the text contain this' — LogicUtil_AContainsB(String)

By daxcay·Created 2 years ago·Updated about a year ago· 159
LogicUtil_AContainsB(String)
    • BOOL
    regex
    input2

    The one-line version

    LogicUtil_AContainsB(String) returns True if a regex pattern matches inside a string, False otherwise. The display name says "AContainsB," but the regex input is not a plain search term - it's a regular expression. That's both the power and the trap. It's how you branch a workflow on the content of a prompt, a filename, or a tag list.

    It's part of the LogicUtil family in ComfyUI-JDCN, the utility pack best known for its folder/file tools. LogicUtil is the pack's logic section, credited to aria1th's ComfyUI-LogicUtils in the source.

    How it works

    The node runs Python's re.search(regex, input2) and returns whether it found a match anywhere in the string. In other words:

    return (True if re.search(regex, input2) else False,)
    

    re.search scans the whole string for a match at any position - so even a plain word works as a simple "is this substring present?" check. But because it's regex, special characters change meaning: a . matches any character, * means "zero or more of the previous thing," and so on.

    Inputs and outputs

    • regex (STRING) - the pattern to search for (default empty)
    • input2 (STRING) - the text to search in (default empty)
    • Output: BOOL - True when the regex matches inside input2

    Note the argument order - the pattern goes in regex, the haystack goes in input2. The naming (A contains B) maps to "B is the pattern, A is the text," which trips people up more often than you'd expect.

    Installing it

    Whole pack, one install:

    Easiest - ComfyUI Manager → Install Custom Node → search ComfyUI-JDCN → install → restart.

    Manual:

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

    Restart ComfyUI. Only dependency is piexif; no models.

    Common issues

    • Your search term is being treated as regex. Search for "girl." and it matches "girls," "girlz," anything with one more character. If you want a literal contains, escape the special chars - re accepts \. for a literal dot - or keep your pattern to plain letters and numbers.
    • Wrong input order. Put your text in input2. Pattern in regex. Get it backwards and you'll match against your pattern as if it were the text, which rarely works.
    • Empty regex matches everything. An empty regex makes re.search succeed on any string, including empty ones. If this node suddenly returns True for everything, check that the pattern field didn't get cleared.

    When you'd actually reach for it

    Routing on text content - "does this filename contain 'upscale'?," "is this tag list missing 'blue'?," "does this prompt mention a style?" - then feed the BOOL into a switch or LogicUtil_ReturnAorBValue. Once you remember it's regex, it becomes one of the more powerful little gates in the pack.

    CategoryLogicUtil

    Inputs (2)

    NameTypeDefaultDescription
    regexSTRING
    input2STRING

    Outputs (1)

    NameTypeDescription
    BOOLBOOL