[^\x00-\xff],可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1),代码示例如下: |
console.info( "abc" .replace( /[^\x00-\xff]/g, "aa" ).length ) // 3 |
console.info( "汉字" .replace( /[^\x00-\xff]/g, "aa" ).length ) // 4 |
console.info( "abc汉字" .replace( /[^\x00-\xff]/g, "aa" ).length ) // 7 |