OdinSam Regex
One ComfyUI regex node for match, extract, and replace. The output socket follows the operation.
中文说明见 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).