在javascript中,我想删除所有unicode或非英语字符。但是我想保留表情符号unicode..and,我需要工作表情符号,有人知道吗?
msg = msg .replace(/[\r\n]|[^a-zA-Z0-9\!\?\;\:\$\#\@\*\%\,\'\"\<\>\+\(\)\.\-\_]/g, ' ');此代码删除所有非英语字符,也删除笑脸unicode。如何保持我使用的https://github.com/danbovey/EmojiPanel作为表情符号的笑脸unicode。
发布于 2018-09-20 07:15:54
使用此正则表达式可以保留表情符号和ascii英文字符,并删除其他所有内容:/[\r\n]|[^\uD83C-\uDFFFa-zA-Z0-9\!\?\;\:\$\#\@\*\%\,\'\"\<\>\+\(\)\.\-\_]/g。例如:
$("#test").click(function() {
var msg = $('.foo').text();
msg = msg.replace(/[\r\n]|[^\uD83C-\uDFFFa-zA-Z0-9\!\?\;\:\$\#\@\*\%\,\'\"\<\>\+\(\)\.\-\_]/g, '');
$('.foo').text(msg);
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="foo">あいうえおかがきぎくぐけこさざしじすせそただちぢつてとなにぬねのはばぱひふへほまみむ test あいうえおかがきぎくぐけこさざしじすせそただちぢつてとなにぬねのはばぱひふへほまみむ</div>
<button id="test">remove non ascii except for emoji</button>
发布于 2018-09-20 06:57:44
此代码删除非英语字符。
str="hi سلام 嗨 नमस्ते";
str.replace(/[^\u0000-\u024F]+/g, "");https://stackoverflow.com/questions/52419076
复制相似问题