How to remove ANSI control characters (VT100) from a Java string

I work with automation and use Jsch to connect to remote units and automate some tasks.

I had a problem analyzing the results of the command, because sometimes they come with ANSI Control chars .

I already saw this answer and this other one , but it does not provide any library for do this. I do not want to reinvent the wheel, if any. And I'm not sure about these answers.

Right now, I'm trying to do this, but I'm not sure if that is enough.

reply = reply.replaceAll("\\[..;..[m]|\\[.{0,2}[m]|\\(Page \\d+\\)|\u001B\\[[K]|\u001B|\u000F", "");

How to remove ANSI control characters (VT100) from Java string?

+4
source share
1

ANSI VT100 ESC [, , ;, , ;. -

reply = reply.replaceAll("\u001B\\[[\\d;]*[^\\d;]","");

reply = reply.replaceAll("\\e\\[[\\d;]*[^\\d;]","");  // \e matches escape character
,

. , . ( .)

, , \\[, escape-, , - , , , ESC.

+4

All Articles