• 将包含emoji图文字符串转换为数组


    <html>
    <header>
        <title>测试emoji字符长度</title>
    </header>
    <body>
        <script type="text/javascript">
            let rsAstralRange = '\\ud800-\\udfff',
                rsZWJ = '\\u200d',
                rsVarRange = '\\ufe0e\\ufe0f',
                rsComboMarksRange = '\\u0300-\\u036f',
                reComboHalfMarksRange = '\\ufe20-\\ufe2f',
                rsComboSymbolsRange = '\\u20d0-\\u20ff',
                rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange;
            let reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
    
            let rsFitz = '\\ud83c[\\udffb-\\udfff]',
                rsOptVar = '[' + rsVarRange + ']?',
                rsCombo = '[' + rsComboRange + ']',
                rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
                reOptMod = rsModifier + '?',
                rsAstral = '[' + rsAstralRange + ']',
                rsNonAstral = '[^' + rsAstralRange + ']',
                rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
                rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
                rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
                rsSeq = rsOptVar + reOptMod + rsOptJoin,
                rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
            let reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
    
            function toArray(val) { // 字符串转成数组
                return hasUnicode(val)
                    ? unicodeToArray(val)
                    : asciiToArray(val);
            }
    
            function hasUnicode(val) {
                return reHasUnicode.test(val);
            }
    
            function unicodeToArray(val) {
                return val.match(reUnicode) || [];
            }
    
            function asciiToArray(val) {
                return val.split('');
            }
    
            var str = "zhang‍❤️‍‍12366";
            var arr = toArray(str);
            for (var i in arr) {
                console.log(arr[i]);
                document.write(arr[i]);
                document.write("<br/>");
            }
        </script>
    </body>
    </html>
  • 相关阅读:
    Rolling File Appender使用示例
    log4net生成dll文件
    看涨期权(call options)
    log4net file Appender使用示例
    log4net不能记录日志,IsErrorEnabled值为false
    C#委托
    打印事件处理顺序
    Zigbee、WiFi和433MHz无线技术
    log4net Tutorial
    安装服务出现异常
  • 原文地址:https://www.cnblogs.com/yiyanwei/p/15881995.html
Copyright © 2020-2023  润新知