Esta expresión regular apuntará a sentenses con una longitud máxima de 25.
/(?<=^|\.)\s*.{1,25}?\./gmsFragmento de prueba:
const regex = /(?<=^|\.)\s*.{1,25}?\./gms; const str = `This is a test. Keep this longer text that has over 25 characters. Remove this small text. `; const result = str.replace(regex, ''); console.log(result);O sin mirar atrás. Para los navegadores que se quedan atrás.
/(^|\.)\s*.{1,25}?\./gmsSustituir con el primer grupo de captura.
const regex = /(^|\.)\s*.{1,25}?\./gms; const str = `This is a test. Keep this longer text that has over 25 characters. Remove this small text. `; const result = str.replace(regex, '$1'); console.log(result);Tal vez este ayude. No consideré el '.' char Porque llené esta oración en JS.
const sentence = (() => { const sentences = []; for (let i = 0; i < 15; i++) { const len = Math.floor(Math.random() * (30 - 15 + 1) + 15); const sentence = []; for (let j = 0; j < len; j++) { sentence.push(String.fromCharCode(Math.floor(Math.random() * (122 - 97 + 1) + 97))); } sentences.push(sentence.join('')); } return sentences })(); console.log(sentence.length) console.log(sentence) console.log(sentence.filter(s => s.length > 24)) console.log(sentence.filter(s => s.length > 24).length)