@KambulovDanil

Как удалить системные символы кодировки utf8 из строки?

Добрый день.

Я получаю на выходе следующую строку.
'\x1B[C\x1B(B\x1B[0;1m\x1B[37m\x1B[44mUp/down | q Quit | b Bits/Bytes | +- Update interval (1000ms)\r\x1B[2d\x1B[31m\x1B[40mAddress\x1B[2;39H\x1B(B\x1B[m\x1B[39;49m\x1B[37m\x1B[40m192.168.12.37\r\x1B[3d\x1B[K\x1B[4d\x1B[K\x1B[5d\x1B[K\x1B[6d\x1B[K\x1B[1;63H\r\x1B[C\x1B(B\x1B[0;1m\x1B[37m\x1B[44mColor Bandwidth Meter\x1B(B\x1B[0m\x1B[37m\x1B[44m\x1B[K\r\x1B[2d\x1B(B\x1B[m\x1B[39;49m\x1B[37m\x1B[40m\x1B[K\x1B[3d \x1B(B\x1B[0;1m\x1B[31m\x1B[40mInterface\x1B[3;22H Receive\x1B[3;41HTransmit\x1B[3;60H Total\x1B[4;3H\x1B[39;49m\x1B[37m\x1B[40menp0s3\x1B[4;22H 0.00 B/s\x1B[41G 59.93 B/s\x1B[60G 59.93 B/s\x1B[5;3H\x1B(B\x1B[m\x1B[39;49m\x1B[37m\x1B[40menp0s8\x1B[5;25H82.63 kB/s\x1B[5;45H3.31 kB/s\x1B[5;63H85.94 kB/s\x1B[6;3Hlo\x1B[6;25H87.90 B/s\x1B[6;44H87.90 B/s\x1B[6;62H175.80 B/s\x1B[H'


Как мне удалить все ненужные символы. Чтобы строка была читаемой.

пытаюсь сделать так, но все равно что то остается.
let s = '\x1B[C\x1B(B\x1B[0;1m\x1B[37m\x1B[44mUp/down | q Quit | b Bits/Bytes | +- Update interval (1000ms)\r\x1B[2d\x1B[31m\x1B[40mAddress\x1B[2;39H\x1B(B\x1B[m\x1B[39;49m\x1B[37m\x1B[40m192.168.12.37\r\x1B[3d\x1B[K\x1B[4d\x1B[K\x1B[5d\x1B[K\x1B[6d\x1B[K\x1B[1;63H\r\x1B[C\x1B(B\x1B[0;1m\x1B[37m\x1B[44mColor Bandwidth Meter\x1B(B\x1B[0m\x1B[37m\x1B[44m\x1B[K\r\x1B[2d\x1B(B\x1B[m\x1B[39;49m\x1B[37m\x1B[40m\x1B[K\x1B[3d \x1B(B\x1B[0;1m\x1B[31m\x1B[40mInterface\x1B[3;22H Receive\x1B[3;41HTransmit\x1B[3;60H Total\x1B[4;3H\x1B[39;49m\x1B[37m\x1B[40menp0s3\x1B[4;22H 0.00 B/s\x1B[41G 59.93 B/s\x1B[60G 59.93 B/s\x1B[5;3H\x1B(B\x1B[m\x1B[39;49m\x1B[37m\x1B[40menp0s8\x1B[5;25H82.63 kB/s\x1B[5;45H3.31 kB/s\x1B[5;63H85.94 kB/s\x1B[6;3Hlo\x1B[6;25H87.90 B/s\x1B[6;44H87.90 B/s\x1B[6;62H175.80 B/s\x1B[H'

let t = s.replace('\e\[[0-9;]\+[mK]', '');
console.log(t)


ВЫВОД
[C (B [0;1m [37m [44mUp/down | q Quit | b Bits/Bytes | +- Update interval (1000ms)
[2d [31m [40mAddress [2;39H (B [m [39;49m [37m [40m192.168.12.37
[3d [K [4d [K [5d [K [6d [K [1;63H
[C (B [0;1m [37m [44mColor Bandwidth Meter (B [0m [37m [44m [K
[2d (B [m [39;49m [37m [40m [K [3d (B [0;1m [31m [40mInterface [3;22H Receive [3;41HTransmit [3;60H Total [4;3H [39;49m [37m [40menp0s3 [4;22H 0.00 B/s [41G 59.93 B/s [60G 59.93 B/s [5;3H (B [m [39;49m [37m [40menp0s8 [5;25H82.63 kB/s [5;45H3.31 kB/s [5;63H85.94 kB/s [6;3Hlo [6;25H87.90 B/s [6;44H87.90 B/s [6;62H175.80 B/s [H"
  • Вопрос задан
  • 86 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы