1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] re.split with multiple arguments | (or) returns None

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

  1. Stack

    Stack Membro Participativo

    I'm using a regular expression in python and trying to split a chunk of text by period and by exclamation mark. However when I split it, I get a "None" in the result

    a = "This is my text...I want it to split by periods. I also want it to split \
    by exclamation marks! Is that so much to ask?"


    This is my code:

    re.split('((?<=\w)\.(?!\..))|(!)',a)


    Note that I have this (?<=\w).(?!..) because I want it to avoid ellipses. Nevertheless, the above code spits out:

    ['This is my text...I want it to split by periods', '.', None, ' \
    I also want it to split by exclamation marks', None, '!', \
    ' Is that so much to ask?']


    As you can see, where a period or exclamation mark is, it has added a special "None" into my list. Why is this and how do I get rid of it?

    Continue reading...

Compartilhe esta Página