Text Regex (Pro)
Find, rewrite, and extract with real patterns
- text
- matches
- found
Text Regex (Pro) gives you a full Python regex engine inside the graph: search a string with a pattern, rewrite the matches with replacement text that can use backreferences, and get a list of everything that matched plus a simple "did anything match?" boolean. It's the serious end of this pack's text tools - the node you reach for when literal find-and-replace isn't enough.
The classic example, straight from the node's own default: take a phone number like 123-456-7890, pattern (\d{3})-(\d{3}-\d{4}), replace with (\1) \2, and out comes (123) 456-7890. But the real power is what regex lets you do with messy text: pull all the numbers out of an LLM's response, strip HTML-ish tags from pasted text, redact emails and tokens before saving a log, or normalize a filename. And because it reports whether anything matched, it doubles as a text test - "does this output contain a date?" - that can drive a conditional branch further down the graph.
How it works
Under the hood it's Python's re module: compile your pattern, run findall to collect matches, and run sub to produce the rewritten text. The replacement string supports \1, \2 backreferences into capture groups, which is what the phone-number example leans on. The flags dropdown gives you the three you'll actually use - IGNORECASE, MULTILINE, and DOTALL - plus the default None.
The inputs that matter
text- the string to process.pattern- your regex. Remember: it's regex, not literal text.replace- the substitution. Use\1/\2to reinsert captured groups.flags- only needed when case-sensitivity or newlines matter.
Three outputs: text (the rewritten string), matches (a LIST of everything that matched), and found (BOOLEAN, true if at least one match). found is the one you wire into a conditional; matches is great for extracting data to process elsewhere.
Installation
The whole pack installs the same way every time - ComfyUI Manager, searching "DebugPadawan's ComfyUI Essentials", or:
cd ComfyUI/custom_nodes
git clone https://github.com/DebugPadawan/DebugPadawans-ComfyUI-Essentials.git
Restart ComfyUI. No model downloads; the pack's numpy/torch/opencv requirements belong to its image and math nodes, and this one is pure re.
Gotchas
Two things get people. First, an invalid pattern doesn't crash the node - it returns the literal string Regex Error: ... as the text output, with an empty matches list. That's arguably friendly, but it means a typo'd pattern silently poisons everything downstream of the text output instead of failing loudly. Watch the console or check the output string.
Second, the matches list gets weird with capture groups. If your pattern has groups, findall returns tuples, and the node stringifies them - you'll see things like ("123", "456-7890") in the list. If you want clean, flat match strings, avoid capture groups (use non-capturing (?:...) or drop the parens) unless you genuinely want the groups. That one's a genuine "huh?" moment that isn't documented anywhere.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | My phone is 123-456-7890 | — |
| pattern | STRING | (\d{3})-(\d{3}-\d{4}) | — |
| replace | STRING | (\1) \2 | — |
| flagsopt | COMBO | None | 4 options: None, IGNORECASE, MULTILINE, DOTALL |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |
| matches | LIST | — |
| found | BOOLEAN | — |