티스토리 뷰

bash shell 커맨드 출력 결과에서 위와 같이 색상이 추가 되어 나오는 경우가 있습니다. 이런 경우 사용자가 보기에는 좋지만 이를 파싱해서 처리해야 하는 경우 보기가 힘듭니다.

 

python 에서 정규식을 이용하여 색상 코드만 제거할 수 있습니다. 사용 방법은 다음과 같습니다.

 

 

https://stackoverflow.com/questions/14693701/how-can-i-remove-the-ansi-escape-sequences-from-a-string-in-python

 

How can I remove the ANSI escape sequences from a string in python

Here is a snippet that includes my string. 'ls\r\n\x1b[00m\x1b[01;31mexamplefile.zip\x1b[00m\r\n\x1b[01;31m' The string was returned from an SSH command that I executed. I can't use the string in ...

stackoverflow.com

 

반응형
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함