I am trying to convert a string of words and numbers into a list, every item is separated with a space, so using .replace(" ", ",").split(",") would be an easy solution, but unfortunately, sometimes there are multiple words in the object name, and I would like these words to be connected with a _
Example:
office supplies 674.56 570.980487 755.84 682.360029
Expected output:
office_supplies 674.56 570.980487 755.84 682.360029
I have found this: Replace spaces between letters only
And tried to implement it like this:
sample_line = "office supplies 674.56 570.980487 755.84 682.360029"
regex = re.compile(':%s/\v(\a)\s(\a)/\1_\2/g', re.I)
print(re.sub(p, r"\1\2", line))
But it does not seem to replace the spaces, I am not very sharp with regex, but according to the linked issue, it should work.
vimsolution not python\D\s\Dshould look for whitespaces between non-digit characters regex101.com/r/t0kOKw/1