Reason
The telnet protocol supports the use of escape characters to enhance customer display and other special effects. However, the client program using the Telnet protocol has a great deal of interference in reading and analyzing data. How can this problem be filtered out?
Implementation
The telnet mode has ANSI escape characters starting with ESC, which can easily control character color, background and other attributes. Common color escape characters:
The color corresponds to the Telnet ANSI character
Red ESC [31 m
Green ESC [32 m
Yellow ESC [33 m
Blue ESC [34 m
Zihong ESC [35 m
Blue-green ESC [36 m
Black (white) ESC [37 m
Reset ESC [m
It is found that the code is followed by ESC (/x16) and ended with M. With this mode, you can use the re regular expression to facilitate filtering.
Source code
Def _ zyresult (self, S ):
Re. Compile ('(/x1b/[[0-9] * m )')
Return P. sub ('', S)
Tested to fully meet the requirements, O (∩ _ ∩) o...