Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const extractSentences = (text) => {
const txt = text
// Remove all {} tags.
.replace(/\{[\s\S]*?\}\s*/gu, '');
const sentenceEndGrouping = /([.?!])(?:\s+|$)/u;
const puncts = RegExtras(sentenceEndGrouping).map(txt, (punct) => {
return punct;
});
return txt
.split(/[.?!](?:\s+|$)/u)
// Re-add the dot.
.map((sentence, idx) => {
return /^\s*$/u.test(sentence) ? sentence : `${sentence}${puncts[idx] || ''}`;
});
};