0

I am trying to apply the following steps:

  • find everything starts after =" and ends before "
  • fill all the whitespaces with <> in between that pattern and leave other whitespaces as they are

My python script looks like this:

string = 'machine="machine m45" level=info msg="Daemon has completed initialization"' 

matches = re.findall(r'="(.+)"', string) 
for m in matches:
  text = m.replace(' ', '<>')
  string = re.sub(m, text, string)
print(string)

String remains the same on my output.

What I want to have is:

machine="machine<>m45" level=info msg="Daemon<>has<>completed<>initialization"

Could you please help me with this? Thanks.

nilesyrt
  • 7
  • 6

0 Answers0