1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Python replace substring same end

Discussão em 'Python' iniciado por Stack, Julho 20, 2025.

  1. Stack

    Stack Membro Participativo

    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...

Compartilhe esta Página