【发布时间】:2011-12-13 00:41:43
【问题描述】:
我正在编写一个记录终端交互的 Python 程序(类似于 脚本 程序),我想在写入磁盘之前过滤掉 VT100 转义序列。我想使用这样的功能:
def strip_escapes(buf):
escape_regex = re.compile(???) # <--- this is what I'm looking for
return escape_regex.sub('', buf)
escape_regex 应该写什么?
【问题讨论】:
-
检查 webdeveloper.com/forum/showthread.php?t=186004 以获取 PHP 版本。转换成python应该很简单。
-
本着这些其他 cmets 的精神,这里也有一个 TCL 进程,它做同样的事情......wiki.tcl.tk/9673
-
这对我有用:
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"(source)