我正在使用新闻API,由于字符限制,该API部分回复了截断的文本。他们结束与“...”,‘[...]’或没有任何迹象。
我想在最后一句之后删掉所有内容,所以我的文字很干净。
这是我当前的代码:
var shortenText = function (input) {
if (input.search(/\w+\./) > 0) {
return input.substring(0, input.lastIndexOf('.') + 1);
} else {
return input
}
}
问题是日期(2月2日),数字(2.000)或美国弄乱了我的输出。
我需要像lastIndexOf(/ \ w + \ W +。/ G)来找到最后两个词,随后是一个句号,以确定一个句子结束了。但lastIndexOf不与正则表达式工作。 :/
任何想法如何解决此问题?
谢谢!
编辑: 下面是从API响应一些例子:
"description": "The Boston-based investment company, Fidelity, has just confirmed rumors about a new cryptocurrency trading platform and custodian service for institutional investors. The firm has also announced that the project is in the final testing phase. In October 2018, the company set up FDAS (Fidelity Digital Asset Services) — a subsidiary dedicated to working with digital […]"
"description": "The Chicago Board Options Exchange (CBOE) and VanEck refiled their Bitcoin exchange-traded fund (ETF) application. But, there likely won't be a Bitcoin ETF by the end of the year and possibly by the year's end. On January 31, as CCN reported, VanEck announced that it submitted its newly drafted Bitcoin ETF application to the U.S. Securities and Exchange Commission (SEC). The VanEck SolidX...</p>"
"description": "The Securities and Exchanges Commission is looking for a blockchain analysis firm to provide readable crypto data according to a new tender notice. It says: “The U.S. Securities and Exchange"