Skip to content

Instantly share code, notes, and snippets.

@nickwanhere
Created September 14, 2015 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickwanhere/17f6a800960955e7b40e to your computer and use it in GitHub Desktop.
Save nickwanhere/17f6a800960955e7b40e to your computer and use it in GitHub Desktop.
Remove emoji
function toUnicode(theString) {
var unicodeString = '';
for (var i=0; i < theString.length; i++) {
var theUnicode = theString.charCodeAt(i).toString(16).toUpperCase();
while (theUnicode.length < 4) {
theUnicode = '0' + theUnicode;
}
theUnicode = '\\u' + theUnicode;
unicodeString += theUnicode;
}
return unicodeString;
}
function removeEmoji(input)
{
var temp = toUnicode(input);
temp = temp.replace(/\\uD83D\\u.{4}/g,'');
var r = /\\u([\d\w]{4})/gi;
temp = temp.replace(r, function (match, grp) {
return String.fromCharCode(parseInt(grp, 16)); } );
temp = unescape(temp);
return temp;
}
var input = 'ASdasd 🙉🚓🚗🚍 好好';
console.log(input);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment