mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-11 23:00:51 +08:00
Fix regexp outputs and give better signals when there's no result
This commit is contained in:
parent
6f533f2f97
commit
7318e59baf
@ -1,4 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from comfy.node_helpers import export_custom_nodes
|
from comfy.node_helpers import export_custom_nodes
|
||||||
from comfy.nodes.package_typing import CustomNode, InputTypes
|
from comfy.nodes.package_typing import CustomNode, InputTypes
|
||||||
@ -44,10 +45,12 @@ class Regex(CustomNode):
|
|||||||
|
|
||||||
CATEGORY = "regular_expressions"
|
CATEGORY = "regular_expressions"
|
||||||
FUNCTION = "execute"
|
FUNCTION = "execute"
|
||||||
RETURN_TYPES = (MATCH_TYPE_NAME,)
|
RETURN_TYPES = (MATCH_TYPE_NAME, "BOOLEAN")
|
||||||
|
RETURN_NAMES = ("match", "match found")
|
||||||
|
|
||||||
def execute(self, pattern: str = "", string: str = "", flags: int = 0) -> tuple[re.Match]:
|
def execute(self, pattern: str = "", string: str = "", flags: int = 0) -> tuple[re.Match, bool]:
|
||||||
return re.match(pattern=pattern, string=string, flags=flags),
|
match = re.match(pattern=pattern, string=string, flags=flags)
|
||||||
|
return match, match is not None
|
||||||
|
|
||||||
|
|
||||||
class RegexMatchGroupByIndex(CustomNode):
|
class RegexMatchGroupByIndex(CustomNode):
|
||||||
@ -62,10 +65,10 @@ class RegexMatchGroupByIndex(CustomNode):
|
|||||||
|
|
||||||
CATEGORY = "regular_expressions"
|
CATEGORY = "regular_expressions"
|
||||||
FUNCTION = "execute"
|
FUNCTION = "execute"
|
||||||
RETURN_TYPES = (MATCH_TYPE_NAME,)
|
RETURN_TYPES = ("STRING",)
|
||||||
|
|
||||||
def execute(self, match: re.Match, index: int = 0) -> tuple[str]:
|
def execute(self, match: Optional[re.Match], index: int = 0) -> tuple[str]:
|
||||||
return match.group(index),
|
return "" if match is None else match.group(index),
|
||||||
|
|
||||||
|
|
||||||
class RegexMatchGroupByName(CustomNode):
|
class RegexMatchGroupByName(CustomNode):
|
||||||
@ -80,10 +83,10 @@ class RegexMatchGroupByName(CustomNode):
|
|||||||
|
|
||||||
CATEGORY = "regular_expressions"
|
CATEGORY = "regular_expressions"
|
||||||
FUNCTION = "execute"
|
FUNCTION = "execute"
|
||||||
RETURN_TYPES = (MATCH_TYPE_NAME,)
|
RETURN_TYPES = ("STRING",)
|
||||||
|
|
||||||
def execute(self, match: re.Match, name: str = "") -> tuple[str]:
|
def execute(self, match: Optional[re.Match], name: str = "") -> tuple[str]:
|
||||||
return match.group(name),
|
return "" if match is None else match.group(name),
|
||||||
|
|
||||||
|
|
||||||
class RegexMatchExpand(CustomNode):
|
class RegexMatchExpand(CustomNode):
|
||||||
@ -100,8 +103,8 @@ class RegexMatchExpand(CustomNode):
|
|||||||
FUNCTION = "execute"
|
FUNCTION = "execute"
|
||||||
RETURN_TYPES = ("STRING",)
|
RETURN_TYPES = ("STRING",)
|
||||||
|
|
||||||
def execute(self, match: re.Match, template: str = "") -> tuple[str]:
|
def execute(self, match: Optional[re.Match], template: str = "") -> tuple[str]:
|
||||||
return match.expand(template),
|
return "" if match is None else match.expand(template),
|
||||||
|
|
||||||
|
|
||||||
export_custom_nodes()
|
export_custom_nodes()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user