[Python] Removing square brackets from output and stopping regex after first match

Discussão em 'Python' iniciado por Stack, Abril 12, 2025.

  1. Stack

    Stack Membro Participativo

    Python noob here. I'm trying to fix two problems with my current code.

    1. I'm trying to remove the square brackets from my list output
    2. I can't figure out how to stop regex after the first match

    For the first problem I've tried a number of different solutions but without success.

    str()
    "".join()
    .replace"[]",''


    page_content = "carrots apples001 carrots apples002 apples003"

    define_words = 'apples'

    parsed_content = str((re.findall(r"([^.]*?%s[^.]*\.)" % define_words, page_content)))



    I'm currently getting the following output

    [apples001][][][][][apples002 apples003]

    When I should be getting

    apples001

    Any help would be much appreciated and sorry about the messy code!

    Continue reading...

Compartilhe esta Página