[Python] Remove part of a string in python with regex [duplicate]

Discussão em 'Python' iniciado por Stack, Fevereiro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to use a regex to remove off my string all text starting from and after ":q=". I have used the code below but it only removes ":q=". Is anyone be able to help me?

    import re

    string = ":example1:q=dfgghp-yoirjl78/-"

    print(string)

    x = re.sub(r':q=.?','', string)

    Continue reading...

Compartilhe esta Página