js只提取字符串中漢字


 

三、簡單的方法

const test = 'ab碧果果def';

 

 

console.log(test.replace(/[^\u4e00-\u9fa5]/gi, ""));
 

 

一、例子

const test = 'ab碧果果def';
console.log(this.GetChinese(test));

 

 

 

二、代碼

// 只提取漢字
  GetChinese(strValue) { // eslint-disable-line
    if (strValue !== null && strValue !== '') {
      const reg = /[\u4e00-\u9fa5]/g;
      return strValue.match(reg).join('');
    }
    return '';
  }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM