例如下面的字符串news="Waukesha trial: US man sentenced to life for car-ramming attack - BBC NewsBBC HomepageSkip to contentAccessibility HelpYour accountHomeNewsSportReelWorklifeTravelFutureMore menuMore menuSearch BBCHomeNewsSportReelWorklifeTravelFutureCultureMusicTVWeatherSoundsClose menuBBC NewsMenuHomeWar in UkraineCoronavirusClimateVideoWorldAsiaUKBusinessTechScienceMoreStoriesEntertainment ArtsHealthWorld News TVIn PicturesReality CheckNewsbeatLong ReadsUS CanadaUS Elections 2022ResultsWaukesha trial: US man sentenced to life for car-ramming attackPublished11 hours agoSharecloseShare pageCopy linkAbout sharingThis video can not be playedTo play this video you need to enable JavaScript in your browser Media caption, Watch: Emotional testimony from victims familiesA Wisconsin judge has sentenced a man who killed six people and injured 62 by driving through a Christmas parade last year to life in prison A jury convicted Darrell Brooks last month after prosecutors argued he had shown "utter disregard for human life" The court also heard emotional testimony from dozens of survivors and families of victims during sentencing Brooks represented himself in the four-week trial, often interrupting court proceedings In her sentencing on Wednesday, Judge Jennifer Dorow said Brooks had chosen "a path of evil"
我想从上面的字符串中删除前3个句子。如果单词以.或结尾:或者-它的意思是一句话。
怎么做呢?
1条答案
按热度按时间qxgroojn1#
首先,您需要转义双引号,这样的字符串是无效的。其次,您确定以“-”结尾的单词表示句子的结尾吗?在您的示例中,您可以将“car-ramming”和“four-week”拆分。无论如何,您可以将字符串拆分为如下句子:
您将得到一个句子列表,如[sentence 1,sentence 2...],您可以对该列表进行切片以删除前3个句子:
然后可以从新列表中获取一个字符串,如下所示:
唯一的问题是你会把所有的“-”都替换成“.",但正如我所说,我认为“-”实际上并不表示你的例子中句子的结尾。
另一种方法是找到分隔符3次,然后删除该位置的所有字符: