我在 python 中使用 RE 表达式并尝试按句点和感叹号分割一大块文本。但是,当我拆分它时,结果中出现“无”
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?"
这是我的代码:
re.split('((?<=\w)\.(?!\..))|(!)',a)
请注意,我有这个 (?<=\w).(?!..) 因为我希望它避免省略号。尽管如此,上面的代码还是吐出:
['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?']
如您所见,句号或感叹号在哪里,它在我的列表中添加了一个特殊的“无”。为什么会这样,我该如何摆脱它?