[Python] How can I match the start and end in Python's regex?

Discussão em 'Python' iniciado por Stack, Maio 1, 2025.

  1. Stack

    Stack Membro Participativo

    I have a string and I want to match something at the start and end with a single search pattern. How can this be done?

    Let's say we have a string like:

    string = "ftp://www.somewhere.com/over/the/rainbow/image.jpg"


    I want to do something like this:

    re.search("^ftp:// & .jpg$" ,string)


    Obviously, it's incorrect, but I hope it gets my point across. Is this possible?

    Continue reading...

Compartilhe esta Página