WASasquatch / was-node-suite-comfyui

An extensive node suite for ComfyUI with over 210 new nodes
MIT License
1.21k stars 177 forks source link

Find And Replace cannot replace backslashes, nor can it successfully add a single backslash to a parenthesis #335

Open Jellybit opened 9 months ago

Jellybit commented 9 months ago

I have a text file I'm iterating through that has some items like "Honda (car)". Now, I want it to have a backslash in front of each parenthesis character, so that ComfyUI will read the parenthesis characters instead of increasing the strength of "car". I simply cannot get any result but "\\(car\\)", or an error message if I try to fix that result.

Here are some example results:

Find: ( Replace: \( Result: \\(

Find: \\ Replace: \ Result:

Error occurred when executing Text Find and Replace:

bad escape (end of pattern) at position 0

  File "Q:\SD\ComfyUI\Portable\ComfyUI\execution.py", line 155, in recursive_execute
    output_data, output_ui = get_output_data(obj, input_data_all)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Q:\SD\ComfyUI\Portable\ComfyUI\execution.py", line 85, in get_output_data
    return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Q:\SD\ComfyUI\Portable\ComfyUI\execution.py", line 78, in map_node_over_list
    results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Q:\SD\ComfyUI\Portable\ComfyUI\custom_nodes\was-node-suite-comfyui\WAS_Node_Suite.py", line 10139, in text_search_and_replace
    modified_text, count = self.replace_substring(text, find, replace)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Q:\SD\ComfyUI\Portable\ComfyUI\custom_nodes\was-node-suite-comfyui\WAS_Node_Suite.py", line 10143, in replace_substring
    modified_text, count = re.subn(find, replace, text)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "re\__init__.py", line 196, in subn
  File "re\__init__.py", line 317, in _subx
  File "re\__init__.py", line 308, in _compile_repl
  File "re\_parser.py", line 1002, in parse_template
  File "re\_parser.py", line 232, in __init__
  File "re\_parser.py", line 245, in __next

Find: \ Replace: Result:

Error occurred when executing Text Find and Replace:

bad escape (end of pattern) at position 0

  File "Q:\SD\ComfyUI\Portable\ComfyUI\execution.py", line 155, in recursive_execute
    output_data, output_ui = get_output_data(obj, input_data_all)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Q:\SD\ComfyUI\Portable\ComfyUI\execution.py", line 85, in get_output_data
    return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Q:\SD\ComfyUI\Portable\ComfyUI\execution.py", line 78, in map_node_over_list
    results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Q:\SD\ComfyUI\Portable\ComfyUI\custom_nodes\was-node-suite-comfyui\WAS_Node_Suite.py", line 10139, in text_search_and_replace
    modified_text, count = self.replace_substring(text, find, replace)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Q:\SD\ComfyUI\Portable\ComfyUI\custom_nodes\was-node-suite-comfyui\WAS_Node_Suite.py", line 10143, in replace_substring
    modified_text, count = re.subn(find, replace, text)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "re\__init__.py", line 196, in subn
  File "re\__init__.py", line 294, in _compile
  File "re\_compiler.py", line 743, in compile
  File "re\_parser.py", line 975, in parse
  File "re\_parser.py", line 232, in __init__
  File "re\_parser.py", line 245, in __next

In the end, it's impossible to use search and replace to make words within parentheses read correctly.

WASasquatch commented 9 months ago

Don't you need to escape backslashes times? \\\