✂️ String Text Extractor
Pull Whatever's Between the Brackets Out of Your Text
- extracted_text
- remainder_text
- extracted_list
✂️ String Text Extractor does one small, genuinely useful thing: given a string and a delimiter pair, it returns whatever is inside the first occurrence. a [red fox] in the snow with delimiters [] gives you red fox, plus the remainder a in the snow, plus a list of every match.
Where that pays off is a prompt you use as a command line. Write [a lighthouse on a cliff] --style anime --ref photo and you can branch the bracketed part somewhere else, or use the delimiters as annotation marks you strip before the encoder. It's the poor man's parser for prompt-with-options schemes, and it costs nothing.
How it works
delimiters is exactly two characters: the opener then the closer. [], (), <>, {} all work. For marks like **bold** or ""quoted"", use the same character twice. Fewer than two characters and the node declines politely - empty extraction, the original text as the remainder, and an empty list.
Matching is non-greedy and multiline (the regex uses DOTALL), so a [...] block that spans a line break still comes out as one match. Non-greedy means [one] [two] gives you one from the first pair and two from the second, rather than swallowing everything between.
The three outputs map cleanly onto the three things you could want:
extracted_text- the content of the first match only.remainder_text- the input with that first match and its delimiters removed, i.e. text before plus text after, concatenated. Note what this means:a [x] bbecomesa bwith two spaces, nota b.extracted_list- every match found, as a list.
No match at all returns an empty extraction, the original string as the remainder, and an empty list. Nothing errors, so an empty extracted_text is your signal that the delimiters aren't in the text.
Multiline delimiters aren't supported - you get two characters, and that's it. Character classes and regex patterns aren't either; the delimiters are escaped before use, so [] is literal brackets, not a character class.
Inputs and outputs
Two required inputs: input_string and delimiters. Three outputs: extracted_text, remainder_text, extracted_list, all strings (or lists of strings).
The pairing with the rest of the pack is the point. Extractor → String Cleaning to tidy the remainder → CLIP Text Encode is a reasonable little prompt-parsing pipeline, and extracted_list feeds anything that wants options one per line.
Install
ComfyUI Manager → search "ComfyUI-mnemic-nodes" → install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/MNeMoNiCuZ/ComfyUI-mnemic-nodes
No models, no API keys, no downloads. The pack's requirements.txt installs dependencies for its other nodes, not this one.
Common issues
Empty extraction. The delimiters aren't in the string, or you passed a single character, or you reversed the pair (][ instead of []).
Double spaces in the remainder. Expected - the delimiters are cut out cleanly and the spaces either side survive. Tidy it with String Cleaning's collapse_sequential_spaces.
Only the first match in extracted_text. By design. Use extracted_list when you want all of them.
Nested delimiters behaving oddly. [a [b] c] with [] gives you a [b - non-greedy matching stops at the first closer. There's no nesting support, so pick delimiters you won't nest.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| input_string | STRING | The text to search. The content of the first delimiter pair comes out as extracted_text, the rest as remainder_text. | |
| delimiters | STRING | Two characters: the opening one, then the closing one, e.g. [] () <> {}. Use the same character twice for marks like ** or "". Fewer than two characters extracts nothing. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| extracted_text | STRING | The content found inside the first instance of the specified delimiters. |
| remainder_text | STRING | The rest of the text after the extracted content and its delimiters have been removed. |
| extracted_list | STRING | A list of all items found between the delimiters. |