1
[1mResolving domain yahoo.com ,[0m ,98.138.253.109  yahoo.com

I want to remove "[1m" and "[0m". I tried encoding using encode('utf-8') didn't worked.

Please help.

smci
  • 32,567
  • 20
  • 113
  • 146
Shreejibawa
  • 1,860
  • 1
  • 25
  • 35

3 Answers3

4

Apparently you're receiving a color-coded string from a VT100-compatible terminal. There should be #27 (0x1b, ESC) symbols in the string, if so, use the regexp eliminating color codes starting with ESC symbols from the string. You can check the possible list of color codes in this Wikipedia article.

Sorry I'm not an expert to write a regexp or Python code, so please use other answers for codes.

Vesper
  • 18,599
  • 6
  • 39
  • 61
1

There's too little information in the question, but I think the following should do it:

import re
s = '[1mResolving domain yahoo.com ,[0m ,98.138.253.109    yahoo.com'
t = re.sub('\[\dm', '', s)
Sufian Latif
  • 13,086
  • 3
  • 33
  • 70
1
a="[1mResolving domain yahoo.com ,[0m ,98.138.253.109  yahoo.com"
c=["[1m","[0m"]
for i in c:
  a=a.replace(i,"")
print a

if you want remove any more ,you can add it to list c

Nandha Kumar
  • 413
  • 8
  • 18