25 lines
725 B
Python
25 lines
725 B
Python
def remove_trailing_content(text, delimiter='---'):
|
|
"""
|
|
剔除文本中最后一个指定分隔符及其后面的内容。
|
|
|
|
参数:
|
|
text (str): 输入的文本
|
|
delimiter (str): 要查找的分隔符,默认为 '---'
|
|
|
|
返回:
|
|
str: 剔除分隔符及其后面内容后的文本
|
|
"""
|
|
index = text.rfind(delimiter)
|
|
if index != -1:
|
|
return text[:index].strip()
|
|
return text
|
|
|
|
import re
|
|
|
|
def remove_grok_render_tags(text: str) -> str:
|
|
if not text:
|
|
return text
|
|
cleaned = re.sub(r'<\s*grok:[^>]+?>[\s\S]*?<\s*/\s*grok:[^>]+?>', '', text, flags=re.IGNORECASE)
|
|
cleaned = re.sub(r'<\s*grok:[^>]+?/?>', '', cleaned, flags=re.IGNORECASE)
|
|
return cleaned
|