Regex Node (Yogurt Nodes)
Extract and Rewrite Text With Regex, Inside Your Graph
- text
LLM nodes hand you text, and text is messy. Prompt generators throw in formatting, vision models ramble, and every caption comes back wrapped in whatever structure the model decided on. YogurtRegexNode is the text-cleaning workhorse: full Python regex, two modes, and capture-group support, all inside the graph.
text- the multiline input.pattern- a Python regex. Flags like(?s)for DOTALL are supported, so.can match newlines when you need it.mode-extractkeeps the matched content,replaceswaps it out.format_or_replacement- in extract mode, the format for each match; in replace mode, the replacement string. Both support group references like\g<1>.count- if positive, operate on the first N matches; if negative, the last N; zero means all.joiner- extract mode only: the string used to join multiple extracted results.
Output: text, a single STRING.
The two modes, concretely
Extract is for pulling things out. Grab a number out of a sentence - pattern \d+(\.\d+)? - and if multiple matches exist, they get joined by your joiner (a comma, a space, nothing). Want just the part of a URL after the domain? Pattern with a capture group, format_or_replacement = \g<1>.
Replace is for scrubbing. Strip markdown, normalize whitespace, remove phone numbers from a caption - the pattern finds it, the replacement swaps it. Since count works here too, you can replace only the first occurrence or only the last, which is a surprisingly handy degree of control.
Where it fits
It slots in right after an LLM output - cleaning a generated prompt before it reaches your conditioning, pulling a numeric value out of an "analysis" response to feed a control node, or stripping artifacts from a caption before a save. If you've ever piped LLM text into a workflow and watched a stray newline break something, this is the fix point.
Install
Ships in ComfyUI-YogurtNodes:
cd ComfyUI/custom_nodes
git clone https://github.com/yogurt7771/ComfyUI-YogurtNodes.git
cd ComfyUI-YogurtNodes
pip install -r requirements.txt
or install ComfyUI-YogurtNodes via ComfyUI Manager and restart. It's under "Yogurt Nodes", display name "Regex Node (Yogurt Nodes)". No models, no keys.
Gotchas: regex special characters in your pattern need escaping, and \g<1> group references work as advertised but only when the pattern actually has capture groups - a pattern with no groups makes \g<1> point at nothing. Test your pattern somewhere with live feedback before wiring it into a long batch; a wrong regex will cheerfully mangle every string that passes through.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | The input text to process. Supports multiline content. | |
| pattern | STRING | The regular expression pattern. Supports Python regex syntax, including flags like (?s) for DOTALL. | |
| mode | COMBO | extract | The operation mode: 'extract' or 'replace'. extract keep the matched content as `format_or_replacement`, replace replace the matched content with `format_or_replacement`. |
| format_or_replacement | STRING | In 'extract' mode, this is the output format for each match (supports group refs like \g<1>). In 'replace' mode, this is the replacement string (supports group refs). | |
| count | INT | 0 | In 'extract' or 'replace' mode: If positive, operate on the first count matches; if negative, operate on the last abs(count) matches; if zero or abs(count) exceeds total matches, operate on all. |
| joiner | STRING | Only used in 'extract' mode. The string used to join multiple extracted results. Default is empty. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |