Nodes/ComfyUI-iTools/Regex Editor
ComfyUI Node

Regex Editor

A regex node that doesn't make you memorize the pattern

By MohammadAboulEla·Created 2 years ago·Updated 27 days ago· 237
Regex Editor
    • match
    text_in
    regex_pattern
    pattern_pickercustom
    replace_match
    replace_non_match

    Most regex nodes make you write the pattern. That's the hard part for most people, and it's where the Regex Editor from iTools is genuinely nice: it ships a dropdown of 27 ready-made patterns - email, phone_number, digit, whitespace, word_character, contains_hello, cat_or_dog, starts_with_abc, double_quoted, in_parentheses and friends - and picking one fills the pattern field for you. You still get a custom slot for your own pattern; the presets are the boring, reliable ones, not clever foot-guns.

    Reach for it when you need to pull something out of a text or reshape a prompt line: extract the number from a batch label, strip quoted segments, transform a list of prompts into variations. It's a string-in / string-out utility, so it slots into prompt pipelines right before a CLIPTextEncode.

    How it works

    Python's re module is the engine, so it's Python regex syntax, not JavaScript's - remember that when you're porting a pattern you found on Stack Overflow. Behavior is split into four modes, controlled entirely by which replacement fields you fill:

    • Both replace_match and replace_non_match empty → returns all matches, joined with no separator.
    • replace_match set only → every match is swapped for the replacement (a global re.sub).
    • replace_non_match set only → matches survive, everything around them becomes the replacement.
    • Both set → a full swap: matches become replace_match, the gaps between them become replace_non_match.

    Nice touch: the node relabels its output pin (match, replace, replace_non_match) depending on which mode you're in, so you're not guessing what the output means.

    Inputs and outputs

    • text_in (STRING) - the text to chew on. Forced as an input, so you can wire it from upstream nodes.
    • regex_pattern (STRING) - the pattern; the picker writes here, or type your own.
    • pattern_picker (enum, default custom) - the 27-preset dropdown.
    • replace_match / replace_non_match (STRING) - the mode switches above.
    • Output: match (STRING).

    Install

    Part of the iTools pack - no separate install. ComfyUI Manager: search ComfyUI-iTools, install, restart, or clone it:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MohammadAboulEla/ComfyUI-iTools
    

    No requirements.txt, no models, nothing to download. It lives under the iTools category in the node menu.

    Where people get burned

    Three things bite. First, when both replace fields are empty, matches come back concatenated with no separator - extracting three things from a line gives you one run-together blob, so put a delimiter in the pattern if you need the pieces separate. Second, output is .strip()-ed, so leading/trailing whitespace gets silently eaten. Third, the phone_number preset is anchored with ^…$, which assumes your whole text is the phone number - running it against a multi-line list matches nothing. If that trips you up, use a custom pattern without the anchors. And when you're swapping matches in prompt text, remember Python regex treats ( and ) as groups - use the Text Replacer sibling node when you mean literal parentheses like (word:1.3).

    CategoryiTools

    Inputs (5)

    NameTypeDefaultDescription
    text_inSTRING
    regex_patternSTRING
    pattern_pickerCOMBOcustom27 options: custom, contains_hello, cat_or_dog, starts_with_abc, ends_with_xyz, any_character, +21
    replace_matchSTRING
    replace_non_matchSTRING

    Outputs (1)

    NameTypeDescription
    matchSTRING