Extensions/OdinSam Regex
ComfyUI Extension

OdinSam Regex

One ComfyUI regex node for match, extract, and replace. The output socket follows the operation.

By odinGitGmail·Created a day ago·Updated a day ago· 0
odinGitGmail/ComfyUI-Odinsam-RegexNodes
Nodes—
On cloudLocal install
Stars0
Updateda day ago
Readme
<div align="center"> <h1>OdinSam Regex</h1> <p> <a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg"></a> <a href="pyproject.toml"><img alt="Version" src="https://img.shields.io/badge/version-0.1.0-blue.svg"></a> <a href="https://github.com/comfyanonymous/ComfyUI"><img alt="ComfyUI" src="https://img.shields.io/badge/ComfyUI-Custom%20Node-00b894.svg"></a> <a href="https://www.python.org/"><img alt="Python" src="https://img.shields.io/badge/Python-%3E%3D3.9-3776AB.svg"></a> </p> <p> <a href="README.md">English</a> · <a href="README.zh-CN.md">中文</a> </p> <p> One ComfyUI node for regex <b>match</b>, <b>extract</b>, and <b>replace</b>. The mode control sits at the top and defaults to extract. The output socket follows the mode. </p> <p> <b>Node:</b> <code>OdinSamRegex</code> / 正则表达式 (OdinSam)<br> <b>Category:</b> <code>OdinSam/Regex</code> </p> <p> <img src="docs/images/node.png" alt="Regex node in the default extract mode" width="420"> </p> </div>

中文说明见 README.zh-CN.md。

Modes

| Mode | Extra inputs | Output | |------|----------------|--------| | 匹配 | none | two BOOLEAN sockets: 真 and 假 | | 提取 | none | STRING list of each full match (default) | | 替换 | 替换内容, 替换次数 | the replaced STRING |

The node normally shows 模式, 字符串, and 正则表达式. Case, multiline, and dotall live under advanced inputs.

替换内容 appears only when the mode is 替换. It is the text that replaces each match and accepts \1 backreferences. 替换次数 appears at the same time; 0 replaces every match.

Extract does not offer the four built-in modes (first match, all matches, first group, all groups). Each list item is the full match, including text outside parentheses.

text     id=123 id=456
pattern  id=(\d+)
extract  id=123
         id=456
replace  replacement num=\1 and count 0 → num=123 num=456

An invalid pattern does not stop the queue: 真 is false and 假 is true, extract returns an empty list, and replace returns an empty string. An empty extract list does not run the downstream node.

Switching away from 匹配 drops links the new socket cannot accept. Extract and replace are both STRING sockets, so an existing string link stays; extract then runs the downstream node once per list item.

OdinSamKit

The node runs without OdinSamKit. web/regex_node.js hides the replace widgets and switches the output socket.

| Piece | Owner | |-------|--------| | Chinese names such as 模式, 正则表达式, 替换内容 | the widget names themselves | | Show 替换内容 and 替换次数 only for 替换 | this pack's frontend; the same rule is also embedded for KIT visibility | | Switch the socket among 真/假, a STRING list, and a STRING | web/regex_node.js |

KIT can add or remove sockets of one type. It cannot turn one socket from BOOLEAN into a STRING list, so this pack owns that switch. With OdinSamKit installed, remaining English keys such as string pick up Chinese labels.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/odinGitGmail/ComfyUI-Odinsam-RegexNodes.git ComfyUI-Odinsam-RegexNodes

Restart ComfyUI. Menu: 正则表达式 (OdinSam) (category OdinSam/Regex).