I am using a node within a webui called ComfyUI, this UI is python based, and uses a…
- User
I am using a node within a webui called ComfyUI, this UI is python based, and uses a node graph for its workflows, I am using a custom node called Replace String, it has three string parameters, String, Regex and ReplaceWith, my understanding is it uses Regex as a regex matcher, String is what it runs the regex on, and any matches it replaces with ReplaceWith, however this is the error I am getting:
!!! Exception during processing!!! missing { at position 6 Traceback (most recent call last): File "D:\AI Generation\Software\ComfyUI_windows_portable\ComfyUI\execution.py", line 151, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\AI Generation\Software\ComfyUI_windows_portable\ComfyUI\execution.py", line 81, in get_output_data return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\AI Generation\Software\ComfyUI_windows_portable\ComfyUI\execution.py", line 74, in map_node_over_list results.append(getattr(obj, func)(**slice_dict(input_data_all, i))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\AI Generation\Software\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-LogicUtils\logic_gates.py", line 378, in replace return (re.sub(Regex, ReplaceWith, String),) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "re\__init__.py", line 185, in sub File "re\__init__.py", line 294, in _compile File "re\_compiler.py", line 743, in compile File "re\_parser.py", line 982, in parse File "re\_parser.py", line 457, in _parse_sub File "re\_parser.py", line 772, in _parse File "re\_parser.py", line 457, in _parse_sub File "re\_parser.py", line 541, in _parse File "re\_parser.py", line 403, in _escape re.error: missing { at position 6 - Assistant
- User
I should have mentioned I have Regex set to: (?<=\N)\n+(?=\N) ReplaceWith is simply one character: | And String is loaded from a file containing Stable Diffusion prompts, one per line, which is why I am trying to replace newlines with |. I should add another place I am using the same Replace String node, but it works fine, I have the Regex in the one that works set to: (?<=\S)\s*[,]+\s*(?=\S) ReplaceWith is set to the same character as the other one: | But the input is a coma separated list obtained from the metadata of a Stable Diffusion LoRA, which contains keywords that it was trained on, yet this one does not get that expecting { error message.
- Assistant
- User
I see, so the issue is \N doesn't work in pythons regex module, but on the website I used to build the regex, regex101.com, it does work. The reason I check for \N before and after, is because I do not want to match newlines at the start or end of the file, so I wanted to ensure it is surrounded by something not a newline on both sides.
- Assistant
- User
Thank you, since I am not coding this, but using a node graph based system, I don't need the python code, but swapping to
(?<!\n)\n+(?!\n)did indeed work for what I wanted it to do - Assistant
Great to hear that the updated pattern worked for your needs! It's good to know that you're using a node graph-based system like ComfyUI, and I'm glad the solution fits within that framework.
Final Regex Pattern:
(?<!\n)\n+(?!\n)
Explanation:
(?<!\n): Ensures the newline is not preceded by another newline.\n+: Matches one or more newline characters.