htmla = `<h1>嘿嘿</h1><h2>哈哈</h2>`;
function get_zw(htmla){ var arrb = []; var str = ""; var reg = /^[u4e00-u9fa5]$/; for(var i = 0; i < htmla.length; i++){ if( reg.test(htmla[i].toString())){ str += htmla[i]; }else{ if(str != "" && !reg.test(htmla[i])){ arrb.push(str); } str = ''; } } return arrb; }
var arr_name = get_zw(htmla);
console.log(arr_name); //这里是一个数组 ["嘿嘿", "哈哈"]
另一种就是
var card ='qweq嘿嘿dasd哈哈'; card=card.match(/[u4e00-u9fa5]/g).join(""); console.log(card); // '嘿嘿哈哈'