I need to change white space to a character, but only if there are two or more white spaces and there is only one I want to keep it.
An example of text is:
142526 0x8520003 2 2022-10-20 The interface status changes. (ifName=Gig.
I need:
142526;0x8520003;2;2022-10-20 The interface status changes. (ifName=Gig.
I use:
';'.join(headers.split())
but change one space white also. Thanks!!
>Solution :
Use re.split() to match more than one space.
import re
new_headers = ';'.join(re.split(r'\s{2,}', headers)
\s matches whitespace, and {2,} means to match 2 or more of them in a row.