.subString до конца последнего предложения - PullRequest
0 голосов
/ 02 февраля 2019

Я использую API новостей, который частично отвечает обрезанным текстом из-за ограничения символов.Они заканчиваются на «...», «[...]» или без каких-либо указаний.

Я хочу обрезать все после последнего предложения, поэтому у меня есть чистый текст.

Это мой текущий код:

var shortenText = function (input) {
        if (input.search(/\w+\./) > 0) {
            return input.substring(0, input.lastIndexOf('.') + 1);
        } else {
            return input
        }
    }

Проблема в том, что даты(2. февраля.), Цифры (2.000) или США портят мой вывод.

Мне нужно что-то вроде lastIndexOf (/ \ w +. \ W +. / G), чтобы найти последние два слова,с последующей полной остановкой, чтобы определить оконченное предложение.Но lastIndexOf не работает с Regex.: /

Есть идеи, как решить эту проблему?

Спасибо!

Редактировать: Вот несколько примеров ответа 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"

1 Ответ

0 голосов
/ 03 февраля 2019

Хорошо, я просто пойду с этим плагином: https://github.com/Tessmore/sbd

Не самый красивый способ, но он подойдет.

...