[Python] Match characters between square brackets but only if text inside brackets follows...

Discussão em 'Python' iniciado por Stack, Janeiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    I want to match text inside of square brackets - but ONLY if it contains hashtag+digit+digit

    i.e [#18] or [hello #25 bye]

    NOT [25] (no hashtag)

    I ultimately want to remove these match strings (including the brackets & ALL the text inside the brackets).

    For example

    12345 one two [#13 west] words [2025/02/25] #15 [#88]turtles [smth #25 else].


    I would like it changed to:

    12345 one two words [2025/02/25] #15 turtles .


    There will not be any brackets inside the (filter out) brackets, only (hashtag, A-z, 0-9 and space). I got it working for the brackets and hashtag+digit+digit, but not the optional words.

    Continue reading...

Compartilhe esta Página