`1♣2♣`.replace(new RegExp('♣️', 'gim'), '-')
// ♣2♣
`1♣2♣`.replace(new RegExp('1', 'gim'), '-')
// -♣2♣
'♣️'.length
// 2
请问这是为什么呢?
如何替换 ♣️
这种特殊符号呢?
`1♣2♣`.replace(new RegExp('♣️', 'gim'), '-')
// ♣2♣
`1♣2♣`.replace(new RegExp('1', 'gim'), '-')
// -♣2♣
'♣️'.length
// 2
请问这是为什么呢?
如何替换 ♣️
这种特殊符号呢?
你new RegExp 用的梅花和你字符串中的梅花不是同一个梅花。。。
'♣' === '♣️' // false
encodeURIComponent('♣') // "%E2%99%A3"
encodeURIComponent('♣️') // "%E2%99%A3%EF%B8%8F"
`1♣2♣`.replace(new RegExp('♣', 'gim'), '-')
var a = '♣'
console.log(a.charCodeAt(0)) // 9827
console.log(a.charCodeAt(1)) // NaN
var b = '♣️'
console.log(b.charCodeAt(0)) // 9827
console.log(b.charCodeAt(1)) // 65039
"️" === "" // false
后面跟了个不可见字符。
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答5.1k 阅读✓ 已解决
3 回答1.8k 阅读✓ 已解决