js 获取包含emoji的字符串的长度
let emoji_exp = /(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g;
function estring(str) {
const ms = [...str.matchAll(emoji_exp)];
if (!ms || !ms.length) return str.length;
let emojiSize = 0;
for (const m of ms) emojiSize += m.length - 1;
return str.length - emojiSize;
}
console.log(estring("❤️❤️a🎅")); // 4