diff --git a/README.md b/README.md index b4c5671..6a189b3 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ Custom nodes for ComfyUI that provide text/string manipulation capabilities. Particularly useful for modifying text from LLM outputs (Ollama, Claude.ai, OpenAI ChatGPT), such as prompts or image-to-text description results. -![stringstrip](stringstrip.png)![stringreplace](stringreplace.png) - ## Features - Remove or replace text, words, numbers in input strings - Handle multi-word strings (partial sentences/phrases) @@ -11,7 +9,9 @@ Custom nodes for ComfyUI that provide text/string manipulation capabilities. Par - Whole string matching option ## String Strip Node -Removes specified strings from input text. Each line should contain the string to be searched. The string can contain multiple words. To match individual words/strings place on seperate lines. +Removes specified strings from input text. Each line should contain the string to be searched. The string can contain multiple words. To match individual words/strings place on seperate lines. +![stringstrip](stringstrip.png) + ### Inputs - **`input_string`**: The string or text to process @@ -24,11 +24,13 @@ Removes specified strings from input text. Each line should contain the string t ![examplestrip](examplestrip.png) ## String Replace Node -Replaces text strings with new strings. Each line should contain a search and replace pair separated by a colon `:` See example image below. +Replaces text strings with new strings. Each line should contain a search and replace pair separated replace_delimiter. See example image below. +![stringreplace](stringreplace.png) ### Inputs - **`input_string`**: The string or text to process - **`replacement_pairs`**: List of search:replace pairs (one per line) +- **`replacement_delimiter`**: Character(s) that separate search and replace strings. Default is a double colon `::` - **`match_case`**: Enable/disable case-sensitive matching - **`match_whole_string`**: Ensure only exact matches are replaced - **`remove_extra_spaces`**: Clean up extra spaces after replacement diff --git a/examplereplace.png b/examplereplace.png index bc40d3e..600141a 100644 Binary files a/examplereplace.png and b/examplereplace.png differ diff --git a/examplestrip.png b/examplestrip.png index 84ce46a..fab531d 100644 Binary files a/examplestrip.png and b/examplestrip.png differ diff --git a/pyproject.toml b/pyproject.toml index 588c584..72e508b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui_stringessentials" description = "Essential string manipulation nodes for ComfyUI." -version = "1.0.0" +version = "1.0.1" license = "MIT" [project.urls] diff --git a/string_replace_node.py b/string_replace_node.py index 0ae8adc..b762f98 100644 --- a/string_replace_node.py +++ b/string_replace_node.py @@ -6,10 +6,12 @@ class StringReplaceNode: return { "required": { "replacement_pairs": ("STRING", {"multiline": True, "default": "", - "tooltip": "Enter replacement pairs, one per line, in format 'search:replace'. Example: 'cat:dog' or 'A drawing of:A photo of'"}), + "tooltip": "Enter replacement pairs, one per line. Format: 'searchreplace'. Default delimiter is ':' (colon)"}), + "replacement_delimiter": ("STRING", {"default": "::", + "tooltip": "Character(s) that separate search and replace strings. Default is two '::' (colons)"}), "match_case": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}), - "match_whole_string": ("BOOLEAN", {"default": True, + "match_whole_string": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}), "remove_extra_spaces": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}) @@ -21,16 +23,16 @@ class StringReplaceNode: FUNCTION = "string_replace" CATEGORY = "utils" - def string_replace(self, input_string, replacement_pairs, match_case, match_whole_string, remove_extra_spaces): + def string_replace(self, input_string, replacement_pairs, replacement_delimiter, match_case, match_whole_string, remove_extra_spaces): result = input_string flags = 0 if match_case else re.IGNORECASE for line in replacement_pairs.splitlines(): line = line.strip() - if not line or ':' not in line: + if not line or replacement_delimiter not in line: continue - search_str, replace_str = line.split(':', 1) + search_str, replace_str = line.split(replacement_delimiter, 1) search_str = search_str.strip() replace_str = replace_str.strip() @@ -46,9 +48,7 @@ class StringReplaceNode: result = re.sub(pattern, replace_str, result, flags=flags) if remove_extra_spaces: - # Replace multiple spaces with single space result = re.sub(r'\s+', ' ', result) - - # Strip leading and trailing spaces - result = result.strip() + result = result.strip() + return (result,) \ No newline at end of file diff --git a/stringreplace.png b/stringreplace.png index 4135ee7..7a3e4c6 100644 Binary files a/stringreplace.png and b/stringreplace.png differ diff --git a/stringstrip.png b/stringstrip.png index 7571a86..f0bc310 100644 Binary files a/stringstrip.png and b/stringstrip.png differ