I have a text file with several lines and several values per line. I want to replace the values, but the new values must end where the original ones end. My code doesn't work because the new character is inserted from where the original ends, and what I want is that regardless of the length they end in the same place. lines = re.sub(r'(?<!\S)(-?\d+(\.\d+)?)(?!\S)', '100', lines) Continue reading...