[Python] Optional \s inside group not getting captured [duplicate]

Discussão em 'Python' iniciado por Stack, Junho 26, 2025.

  1. Stack

    Stack Membro Participativo

    I have this string:

    "232_0452 Render 2.mov"


    And this regex:

    .*(\s?[Rr]ender).*


    If I execute:

    match = re.match(r'.*(\s?[Rr]ender).*', "232_0452 Render 2.mov")
    print(match.group(1))


    I expect the output to be " Render". Instead it is "Render"

    Why does the optional white space character not get captured to the group, and how can I write this so that it does?

    Continue reading...

Compartilhe esta Página