js只提取字符串中汉字

一、例子

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 '';
  }

猜你喜欢

转载自www.cnblogs.com/wangyuxue/p/12072362.html
今日推荐