Nodes/ComfyUI 1hewNodes/Text Match Rownum
ComfyUI Node

Text Match Rownum

Which line does this match? Ask, and get a number

By 1hew·Created about a year ago·Updated 7 days ago· 33
Text Match Rownum
    • int
    text_multiline
    text_single

    Some workflows are basically lookup tables wearing a graph costume. You have a list of options as text - one per line - and a value from elsewhere, and you need to know where that value sits in the list. Text Match Rownum does exactly that: match a single string against the lines of a multiline block and return the row number. 1-based, because of course it is. No match? Zero.

    What it's for

    The use case is indexing. You've got a comma-separated config that's really an array in disguise, a prompt library where each line is a variant, a settings file where order means something - and a value that should select one of them by position. The row number is the bridge to anything that takes an index: pick the Nth prompt, the Nth setting, the Nth element of a parallel list. Combined with the pack's other logic nodes, it's how a string becomes a choice.

    How it works

    Dead simple, and that's the appeal. The single-line input is trimmed, each line of the multiline block is trimmed and compared with exact string equality, and the first line that matches wins, returning its 1-based index. The search is strictly top-down and strictly exact - no substring matching, no fuzzy logic, no regex. If nothing matches, you get 0, which is the standard "not found" sentinel you can branch on.

    The one subtlety: because it's exact-after-trim, whitespace won't sabotage a match, but case and spelling absolutely will. "Cat" does not match "cat".

    The inputs that matter

    • text_multiline (STRING, multiline) - the lookup table, one entry per line.
    • text_single (STRING, single-line) - the value to find.

    One output:

    • int (INT) - the 1-based row number, or 0 if no match.

    Installing it

    ComfyUI Manager → search ComfyUI-1hewNodes → install → restart, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/1hew/ComfyUI-1hewNodes
    

    Restart ComfyUI. Pure string logic - no models, no downloads. The pack's requirements pull heavy packages regardless (rembg, ultralytics, etc.), and it targets ComfyUI's newer comfy_api.latest API, so update ComfyUI if the node doesn't appear.

    Common issues

    The exact-match contract trips people up more than anything: if your single-line value has trailing spaces from a text node, or the list lines have stray punctuation, you get 0 and no error to explain why. Trim on both sides is handled, so focus on case and invisible characters. Duplicate lines? You always get the first occurrence - the search stops at the first exact hit, which is usually what you want but worth remembering if your table has repeats. And 0 for not-found is easy to misread as "row zero"; it means "no such line," so branch on it deliberately rather than feeding it to an indexer that expects a real position.

    Category1hewNodes/logic

    Inputs (2)

    NameTypeDefaultDescription
    text_multilineSTRING
    text_singleSTRING

    Outputs (1)

    NameTypeDescription
    intINT