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 '';
  }
posted @ 2019-12-20 11:52  碧果果  阅读(10265)  评论(1编辑  收藏  举报