Skip to content

Instantly share code, notes, and snippets.

@detj
Created May 21, 2013 10:38
Show Gist options
  • Save detj/5618900 to your computer and use it in GitHub Desktop.
Save detj/5618900 to your computer and use it in GitHub Desktop.
Strip anything other than ASCII. Note: This also removes Chinese, Japanese and other Unicode characters.
var re = /(?![\x00-\x7F]|[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3})./g;
var str = "カナダ假借字A�युनिकोड";
str.replace(re, ""); // "A"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment