.subString直到最后一句结束

问题描述 投票:0回答:1

我使用的是新闻的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"
javascript regex substring lastindexof
1个回答
0
投票

好吧,我会简单地用这个插件可以走:https://github.com/Tessmore/sbd

不是最漂亮的方式,但它会做。

© www.soinside.com 2019 - 2024. All rights reserved.