import re
def remove_identifiers_and_content(original_string, identifier_A, identifier_B):
# 将标识符A和B转换为正则表达式,以匹配它们及其之间的任何内容
pattern = f"{identifier_A}.*?{identifier_B}"
# 使用re.sub()函数替换掉匹配的模式
modified_string = re.sub(pattern, "", original_string, flags=re.DOTALL)
return modified_string
if __name__ == '__main__':
content = """
```searchSource
[{"index":1,"source":"ht。"}]
```
具体介绍:
"""
# sub = re.sub('```searchSource.*?```', '', content)
sub = remove_identifiers_and_content(content, '```searchSource', '```', )
print(sub)
01-03
2万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)