ComfyUI Node

Prompt Regex Remove

Scrub tags from a prompt with a regex — clean output, zero fuss

By aws-samples·Created 2 years ago·Updated about a year ago· 30
Prompt Regex Remove
    • STRING
    prompt
    regex_string

    Sometimes the problem isn't getting a prompt, it's getting rid of half of it. This node takes a prompt string, applies a regex, and deletes everything that matches. That's the whole job, and it's a genuinely handy one in this pack.

    How it works

    It runs Python's re.sub(regex_string, "", prompt) - replace every match of your pattern with nothing. No LLM, no API, no AWS. It's a pure string utility that happens to live in a Bedrock pack, in the "utils" category where it belongs.

    The two inputs are both multiline: prompt (the string to clean) and regex_string (the pattern to delete). Output is the scrubbed STRING.

    Why you'd reach for it

    • Strip junk tags before a generation. Remove a set of booru tags you no longer want, like masterpiece, best quality, in one pass.
    • Clean LLM output. The pack's JSON Text Extraction node fails on JSON wrapped in markdown fences - run the LLM text through a regex like ```json|``` first and the JSON parses cleanly.
    • Normalize a prompt pipeline. Drop repeated keywords, stray brackets, or the leftover {prompt} artifacts a template left behind.

    Installing it

    cd ComfyUI/custom_nodes
    git clone https://github.com/aws-samples/comfyui-llm-node-for-amazon-bedrock.git
    pip install -r comfyui-llm-node-for-amazon-bedrock/requirements.txt
    

    Restart ComfyUI, or install via ComfyUI Manager (search "Amazon Bedrock"). Deps are boto3, requests, retry - and again, no AWS credentials needed for this one.

    Gotchas

    • It's Python regex, not JavaScript. The pattern syntax is re - think \d, \s, ^, $. A pattern that works in your browser's dev console may not mean the same thing here. That said, the node itself ships zero escaping helpers, so backslashes in the multiline box are passed through raw - write \. not \.-in-a-JS-string.
    • Deletion, not replacement. There's no substitution here; matched text becomes nothing. Removing ,\s* leaves doubled spaces you may want to tidy separately.
    • Empty output is possible. If the regex matches everything, you get an empty string, and whatever you wire it into will quietly run on nothing.
    • Replaced fully, every occurrence. re.sub hits all matches, not just the first.

    Honest take: installing an entire Bedrock pack for a five-line regex filter feels absurd, but the pack is small and dependency-light, and this node is the freebie that makes the LLM nodes usable. If you only need it for cleaning prompts, it earns its keep the first time an LLM hands you fence-wrapped JSON.

    Categoryutils

    Inputs (2)

    NameTypeDefaultDescription
    promptSTRING
    regex_stringSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING