ComfyUI Node

HT Regex

Regular expressions on your prompts, because 'find and replace' isn't enough

By ArtHommage·Created 2 years ago·Updated about a year ago· 4
HT Regex
    • parsed_text
    input_text
    regex_pattern.*

    Prompts get messy. Batch templates leave stray markers, imported workflows carry tags you don't want, and sometimes you need to yank every number out of a caption or strip all the LoRA <lora:...> tags so the sampler sees only the words. That's text surgery, and ComfyUI's default text nodes can't do it. HT Regex is the pack's scalpel: you give it input_text and a regex_pattern, and it runs Python's re module over the text, returning every match as parsed_text.

    How it works

    Mechanically it's about as simple as a node gets: compile the pattern, re.findall across the input, and if multiple matches land, join them with newlines. The default pattern is .* - "match everything" - which is a fine starting point that effectively passes text through, so you can wire it up, confirm the plumbing, then make the pattern do real work.

    A few patterns you'll actually use:

    • \d+ - extract all numbers. Feed a prompt with embedded sizes or seeds and get them back, one per line.
    • <lora:([^:>]+):[\d.]+> - pull LoRA filenames out of a prompt string (the ([^:>]+) captures the name, so the output is the clean list).
    • \b(?:bedroom|kitchen|forest)\b - filter for specific keywords.
    • (?:^|\s)[A-Za-z']+(?:\s|$) - rough word tokenization.

    Remember it's Python regex, not the simplified "find" you get in editors - that's the power and the trap. A malformed pattern raises a clear re.error, which the node surfaces, so you'll know immediately rather than silently getting nothing back.

    When you'd reach for it

    • Cleaning batch prompts: strip markers, tags, or scaffolding before the text encoder sees them.
    • Extraction for downstream automation: numbers out of text feeding the pack's Parameter Extractor or a seed node.
    • Validation-ish filtering: keep only lines that match, drop the rest.
    • Debugging a text pipeline: a quick regex sanity check on what's actually flowing through a wire.

    Installing

    Standard pack install:

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

    restart, or Manager → "HommageTools for ComfyUI". Zero dependencies beyond Python's standard library - this node is pure stdlib re.

    The honest take

    It's a single-purpose utility, and whether it changes your life depends entirely on whether you already speak regex. If you do, this is exactly the right tool and you'll wonder why it isn't built in. If you don't, the learning curve is real - but a prompt-cleanup workflow is actually a gentle place to start, because the stakes are low and the results are immediately visible. The one genuine limitation: it's findall, not replace. There's no "replace matched text" mode here, so for transformation rather than extraction you'll want it paired with another text node or a dynamic prompt node. And per the pack's alpha disclaimer, the output-joining behavior is simple enough that it should survive updates - still, re-check after upgrading.

    CategoryHommageTools

    Inputs (2)

    NameTypeDefaultDescription
    input_textSTRING
    regex_patternSTRING.*

    Outputs (1)

    NameTypeDescription
    parsed_textSTRING