chore: enhance re_findall function to handle empty patterns and regex errors

--bug=1062401 --user=刘瑞斌 【知识库】知识库文档分段的时候,如果使用的分段标识是文档中不存在的符号,点击生成预览会报错,希望这个报错提示词可以优化一下,方便识别 https://www.tapd.cn/62980211/s/1782047
This commit is contained in:
CaptainB 2025-10-09 13:23:10 +08:00
parent d380a22384
commit 80629b9574

View File

@ -169,7 +169,14 @@ def parse_level(text, pattern: str):
def re_findall(pattern, text):
result = re.findall(pattern, text, flags=0)
if not pattern or not pattern.strip():
return []
try:
result = re.findall(pattern, text, flags=0)
except re.error:
return []
return list(filter(lambda r: r is not None and len(r) > 0, reduce(lambda x, y: [*x, *y], list(
map(lambda row: [*(row if isinstance(row, tuple) else [row])], result)),
[])))