๐โ๐ Replace text
Find-and-replace with regex, and it strips Ollama's <think> tags
- STRING
A plain find-and-replace node, but with enough options bolted on to handle the messy real-world cases a simple swap can't. The concrete example the pack's own changelog calls out is worth leading with: reasoning models routed through the pack's Ollama nodes sometimes wrap their internal reasoning in <think>...</think> tags before the actual answer, and this node - with regex and multiline matching turned on - is what people use to strip that block out before the text hits a display node or a TTS voice.
How it works
input_text is what you're editing, search_text is what to look for, replace_text is what to put in its place. use_regex switches from a literal string match to a full regular expression, which is what makes the <think> tag removal possible in the first place - you can't reliably strip an entire multi-line block with a plain string match, but a regex pattern spanning newlines can, provided you also flip on multiline_regex so the pattern matches across line breaks instead of stopping at each one. replace_count caps how many matches get replaced - leave it at the default and it replaces every occurrence; set it to a specific number and it stops after that many. case_sensitive is on by default, matching exact case only. trim_whitespace runs after the replace and cleans up leftover whitespace at the start, end, or both sides of the result - useful because stripping a tag out of the middle of text often leaves an awkward gap or leading space behind.
The inputs and outputs that matter
input_text/search_text/replace_text(STRING, multiline) - the core find-and-replace trio.use_regex(BOOLEAN, default false) - switch to regex matching for anything a literal string can't express, like matching across a tag pair.multiline_regex(BOOLEAN, default false) - needed alongsideuse_regexif the thing you're matching spans multiple lines.replace_count(INT, default 0) - 0 replaces every match; set a specific number to cap how many get replaced.trim_whitespace(enum:none/left/right/both) - cleans up stray whitespace left behind after the replace.- Output:
STRING- the result, ready to feed onward.
How to install it
Via ComfyUI Manager: search Bjornulf_custom_nodes, install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/justUmen/Bjornulf_custom_nodes
cd Bjornulf_custom_nodes && pip install -r requirements.txt
then restart ComfyUI. No special dependency for this specific node - it's plain string/regex handling - but you're installing the whole 170-node pack and its shared requirements.txt regardless.
Common issues & troubleshooting
A regex pattern that works fine testing elsewhere doesn't match here. The most common cause is forgetting multiline_regex - if your target spans more than one line (like a <think>...</think> block that wraps across several lines), a standard regex . won't match the newlines inside it unless you flip that toggle on alongside use_regex.
Replace works but leaves an awkward blank line or leading space. That's the expected residue of cutting a chunk out of the middle of a text block - set trim_whitespace to both (or whichever side applies) to clean it up automatically instead of chaining on another node just for that.
Case-sensitive matching silently fails to find an obvious match. If search_text doesn't seem to find anything even though you can see it in input_text, check capitalization first - case_sensitive defaults to true, so "Hello" and "hello" won't match each other unless you turn it off.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| input_text | STRING | โ | |
| search_text | STRING | โ | |
| replace_text | STRING | โ | |
| replace_count | INT | 00โ1000 | Number of replacements (0 = replace all) |
| use_regex | BOOLEAN | false | โ |
| case_sensitive | BOOLEAN | true | Whether the search should be case-sensitive |
| trim_whitespace | COMBO | none | Remove whitespace around the found text |
| multiline_regex | BOOLEAN | false | Make dot (.) match newlines in regex |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | โ |