【发布时间】:2019-03-29 11:12:40
【问题描述】:
我希望拆分句子包含标点符号(例如:?、!、.),如果句子末尾有双引号,我也想包含它。
我使用 python3 中的 re.split() 函数将我的字符串拆分为句子。但遗憾的是,生成的字符串不包含标点符号,也不包含双引号(如果句尾出现双引号)。
这是我当前代码的样子:
x = 'This is an example sentence. I want to include punctuation! What is wrong with my code? It makes me want to yell, "PLEASE HELP ME!"'
sentence = re.split('[\.\?\!]\s*', x)
我得到的输出是:
['This is an example sentence', 'I want to include punctuation', 'What is wrong with my code', 'It makes me want to yell, "PLEASE HELP ME', '"']
【问题讨论】:
标签: regex python-3.x string punctuation sentence