Skip to content

Instantly share code, notes, and snippets.

@PCouaillier
Created November 6, 2019 15:31
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 PCouaillier/a063f94144dacbcafa066e7e7f3d703f to your computer and use it in GitHub Desktop.
Save PCouaillier/a063f94144dacbcafa066e7e7f3d703f to your computer and use it in GitHub Desktop.
const cleanUtf8Regex = str => {
let i = 0;
let res = '';
let code;
while(code = str.charCodeAt(i)) {
res += 0x7E < code && code <= 0xFF ? `\\x{${code.toString(16)}}` : str[i];
i += 1;
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment