[Python] Unwanted ending empty string applying Python Regular Expression split method to test...

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

  1. Stack

    Stack Membro Participativo

    In the following Python regular expression, splitting words from a string into a list of substrings, I'm trying to avoid the empty string, '', on the output. Can I adjust the inputs of the regular expression to achieve this?

    In [1]: import re
    In [2]: re.split(r'[.!,;\s]\s*', 'To be or not! to be; that, is the question!')
    Out [2]: ['To', 'be', 'or', 'not', 'to', 'be', 'that', 'is', 'the', 'question', '']


    Resulted in unwanted empty string at end of list apply re.split method.

    Continue reading...

Compartilhe esta Página