【python】使用paramiko获取ssh输出,过滤ANSI Color及ANSI Escape字节串

发布时间 2023-07-25 11:05:25作者: 代码诠释的世界

1、ANSI Color及ANSI Escape

ANSI Escape Codes · GitHub

 

 

2、处理ANSI Color

# 7-bit and 8-bit C1 ANSI sequences
ansi_escape_8bit = re.compile(
    br'(?:\x1B[@-Z\\-_]|[\x80-\x9A\x9C-\x9F]|(?:\x1B\[|\x9B)[0-?]*[ -/]*[@-~])'
)
result = ansi_escape_8bit.sub(b'', somebytesvalue)

 

 

参考链接:

ANSI Escape Codes · GitHub

 如何从 python 中的字符串中删除 ANSI 转义序列_python_Mangs-Python

 

 

 

 

参考链接:

如何从 python 中的字符串中删除 ANSI 转义序列_python_Mangs-Python