使用 javascript 和 jquery 我试图分隔句子并将它们一一存储到一个数组中。这是我尝试过的
var sentenceArray = new Array();
//SPLITS PARAGRAPHS INTO SENTENCES//
$('#text').each(function() {
var sentences = $(this).html().replace(/([^.!?]*[^.!?\s][.!?]['"]?)(\s|$)/g,'<span class="sentence">$1</span>$2');
sentenceArray.push(sentences);
});
但是,这会将所有句子组合到数组的 [0] 索引中。我如何将它们分开?
<div id="text">
Crowds blocked main roads in Sao Paulo and Brasilia, and protesters confronted police in Rio de Janeiro state shortly after the U-turn was announced.
Earlier, there were clashes before Brazil's football team played Mexico in Fortaleza in the Confederations Cup.
Protesters are angry at corruption and high spending on next year's World Cup.
Activists say they have not changed their intention to hold the biggest demonstrations yet on Thursday.
The BBC's Julia Carneiro, in Sao Paulo, says hundreds of thousands are expected on the streets there before another round of matches in the Confederations Cup.
</div>