Nodes/Eden.art nodesuite/Eden_Regex_Replace
ComfyUI Node Runs on cloud

Eden_Regex_Replace

Regex find-and-replace on any text wire, without leaving the graph

By edenartlab·Created 3 years ago·Updated 6 months ago· 119
Eden_Regex_Replace
    • result_string
    source_string
    regex_pattern
    replacement
    max_n_replacements-1
    case_sensitivetrue

    Eden_Regex_Replace is the node you reach for when plain text swapping isn't enough - when you need to strip every <lora:...> tag out of a prompt, yank a number out of a filename, or collapse a pile of inconsistent formatting into one shape. It's a thin wrapper around Python's re.sub, so everything you know about regex transfers: patterns, capture groups, backreferences. If you've never written a regex in your life, it's still worth learning here because this is the cheapest place to practice - you type a pattern, hit run, and see what broke.

    It comes from Eden.art's node suite, the 70+ node pack that powers the creative tools on eden.art. The pack is MIT-licensed and installs like any custom node pack.

    What you set

    • source_string - the text you're processing. Wire it from another string node or type it in.
    • regex_pattern - the search pattern. This is real regex, so . matches anything, \d+ matches digits, [0-9]{4} matches exactly four digits, and (foo|bar) is a group.
    • replacement - what replaces matches. You can use backreferences here: \1 and \2 pull in whatever your capture groups matched. To delete a match, leave this empty.
    • max_n_replacements - cap how many replacements happen. Default -1 means replace all occurrences. Set it to 1 if you only want the first match touched.
    • case_sensitive - on by default. Flip it off and matching becomes case-insensitive, which is handy for cleaning up titles that arrived in mixed case.

    The single output, result_string, plugs straight back into any string input - CLIP text encoders, prompt enhancers, filename builders, you name it.

    Where people get burned

    The regex engine is the same one behind re.sub, and that cuts both ways. The classic beginner trap is feeding it text you think is literal: a period in your "pattern" matches any character, and a ( that isn't closed makes the whole thing blow up. A nice touch is that the node doesn't hard-crash on a bad pattern - it returns a string that starts with REGEX ERROR: <message> followed by your original text. That's a debugging gift, but it also means a failed replace silently flows downstream if you don't notice the prefix, so check the output in a debug view before you trust it in a saved filename.

    Backreferences deserve a mention because they're the power move here. To swap "firstname lastname" to "lastname, firstname" you'd use pattern (\w+) (\w+) and replacement \2, \1. Keep in mind that in a JSON workflow file, backslashes need escaping, so \d shows up as \\d in the raw JSON.

    Installing it

    The pack installs the standard way - ComfyUI Manager (search for eden_comfy_pipelines or "Eden.art nodesuite"), or manually:

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

    Then restart ComfyUI. The requirements line is heavier than this one node needs (it pulls clip-interrogator, transformers, opencv and friends for the rest of the pack), but a plain text node is why you came, and this one runs with zero model downloads and zero API keys. That's the whole appeal: pure Python, no GPU, no secrets, no network.

    CategoryEden 🌱/text

    Inputs (5)

    NameTypeDefaultDescription
    source_stringSTRING
    regex_patternSTRING
    replacementSTRING
    max_n_replacementsINT-1-1–1000000
    case_sensitiveBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    result_stringSTRING