javascript 正则表达式修复NLP

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 正则表达式修复NLP相关的知识,希望对你有一定的参考价值。

const regex = /([^\*])\1{2,}/gm;
let text = 'hhollllllláááááááááááá))))';

let truncatedText = text;
while ((arr = regex.exec(text)) !== null) {
   let match = arr[0];
   let character = match.charAt(0)
   truncatedText = truncatedText.replace(match, character.repeat(2));
}

console.log(`==== Result: ${truncatedText}`);

以上是关于javascript 正则表达式修复NLP的主要内容,如果未能解决你的问题,请参考以下文章