Text Regex Operations
Up to 20 chained regex find/replaces in a single node
- STRING
Caption cleanup, prompt sanitizing, filename fixing - they all eventually turn into "apply these five regex substitutions, in order." Doing that with a chain of text nodes is miserable to build and harder to read. Text Regex Operations runs up to 20 find/replace operations in one node, each with its own pattern, replacement and multiline flag, and hands you the finished string. One node instead of a dozen, and you can see the whole pipeline at a glance.
It's a re.sub pipeline with training wheels. Each operation's pattern runs against the text, its replacement is applied, and the result feeds the next operation. Standard Python regex semantics throughout, which means backreferences work (\1 and friends), character classes work, and if you know regex at all you know what this node does.
How it works
num_operations (1–20, default 1) says how many of the operations actually run. Each operation i has three inputs: pattern_i, replacement_i, and use_multiline_i (a flag that adds Python's re.MULTILINE). The node loops from 1 to num_operations and applies each in turn:
processed_text = re.sub(pattern, replacement, processed_text, flags=flags)
An invalid pattern doesn't crash the run - it prints a regex error to the console and moves on, leaving the text unchanged for that step. That's a friendlier failure mode than most text nodes offer.
The inputs that matter
text- the string you're processing, multiline.num_operations- how many of the 20 possible ops run.pattern_N/replacement_N/use_multiline_N- per-op settings, present for N = 1 through 20.use_multilinedefaults to true for every op.
The README's example shows the shape of it. Input "*Start* of line and some extra text $5.99." with:
- pattern
^\*→ replacement-(bullet to dash) - pattern
\*(.*?)\*→ replacement `` (strip the asterisks) - pattern
\$(.+)→ replacementPrice: \1(label the price)
...produces "-Start of line and some extra text Price: 5.99.". That's a realistic caption-cleanup job in three ops.
Where people get tripped up
The use_multiline default of true matters more than it looks. With the flag on, ^ and $ match at every line boundary; with it off, they anchor to the whole string. For single-line prompts it makes no difference; for multiline text it's the difference between fixing every line and fixing only the first. The author's own example depends on it, so don't flip it off casually.
Two more: operations run in order and each one sees the previous op's output - a later pattern can match text an earlier op just produced, so order is part of your design, not an afterthought. And an empty pattern means the op is skipped entirely, which is how you build a single saved template with fewer than 20 active ops.
Install
Same as every node in this pack: ComfyUI Manager → search "uber_comfy_nodes" ("Suplex Misc ComfyUI Nodes") → install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/saftle/uber_comfy_nodes
Restart, find it under Uber Comfy. Light dependencies (Pillow, numpy, psutil, pynvml), no model downloads.
Inputs (62)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| num_operations | INT | 11–20 | — |
| pattern_1opt | STRING | — | |
| replacement_1opt | STRING | — | |
| use_multiline_1opt | BOOLEAN | true | — |
| pattern_2opt | STRING | — | |
| replacement_2opt | STRING | — | |
| use_multiline_2opt | BOOLEAN | true | — |
| pattern_3opt | STRING | — | |
| replacement_3opt | STRING | — | |
| use_multiline_3opt | BOOLEAN | true | — |
| pattern_4opt | STRING | — | |
| replacement_4opt | STRING | — | |
| use_multiline_4opt | BOOLEAN | true | — |
| pattern_5opt | STRING | — | |
| replacement_5opt | STRING | — | |
| use_multiline_5opt | BOOLEAN | true | — |
| pattern_6opt | STRING | — | |
| replacement_6opt | STRING | — | |
| use_multiline_6opt | BOOLEAN | true | — |
| pattern_7opt | STRING | — | |
| replacement_7opt | STRING | — | |
| use_multiline_7opt | BOOLEAN | true | — |
| pattern_8opt | STRING | — | |
| replacement_8opt | STRING | — | |
| use_multiline_8opt | BOOLEAN | true | — |
| pattern_9opt | STRING | — | |
| replacement_9opt | STRING | — | |
| use_multiline_9opt | BOOLEAN | true | — |
| pattern_10opt | STRING | — | |
| replacement_10opt | STRING | — | |
| use_multiline_10opt | BOOLEAN | true | — |
| pattern_11opt | STRING | — | |
| replacement_11opt | STRING | — | |
| use_multiline_11opt | BOOLEAN | true | — |
| pattern_12opt | STRING | — | |
| replacement_12opt | STRING | — | |
| use_multiline_12opt | BOOLEAN | true | — |
| pattern_13opt | STRING | — | |
| replacement_13opt | STRING | — | |
| use_multiline_13opt | BOOLEAN | true | — |
| pattern_14opt | STRING | — | |
| replacement_14opt | STRING | — | |
| use_multiline_14opt | BOOLEAN | true | — |
| pattern_15opt | STRING | — | |
| replacement_15opt | STRING | — | |
| use_multiline_15opt | BOOLEAN | true | — |
| pattern_16opt | STRING | — | |
| replacement_16opt | STRING | — | |
| use_multiline_16opt | BOOLEAN | true | — |
| pattern_17opt | STRING | — | |
| replacement_17opt | STRING | — | |
| use_multiline_17opt | BOOLEAN | true | — |
| pattern_18opt | STRING | — | |
| replacement_18opt | STRING | — | |
| use_multiline_18opt | BOOLEAN | true | — |
| pattern_19opt | STRING | — | |
| replacement_19opt | STRING | — | |
| use_multiline_19opt | BOOLEAN | true | — |
| pattern_20opt | STRING | — | |
| replacement_20opt | STRING | — | |
| use_multiline_20opt | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |