今天的天气真好啊![得意]走一个~
如何点击按钮删除字符串最后一个字符串
如最后的字符是非表情字符串,则删除上文的最后一个字符,如~
如[得意]在字符串的最后,则删除最后一个匹配的[得意]
以下答案貌似会将在[得意](任意内容)[得意]这样 会将整个由最外层方括号包裹的内容都删除
function native2ascii(str) {
let ascii = '';
for (let i = 0; i < str.length; i++) {
const code = Number(str[i].charCodeAt(0));
let charAscii = code.toString(16);
charAscii = '0000'.substring(charAscii.length, 4) + charAscii;
ascii += `\\u${charAscii}`;
}
return ascii;
}
deleteBack() {
let h = this.content;
const f = /\[(.*?)\]+/g;
const b = h.match(f);
const c = b[b.length - 1];
const regx = new RegExp(`${native2ascii(c)}$`);
if (h.slice(-1) === ']') {
h = h.replace(regx, '');
} else {
h = h.replace(/.$/, '');
}
this.content = h;
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
试试这个:
'今天的天气真好啊![得意]走一个~'.match(/\[.{1,3}\]|./g);