How to remove all non-ASCII characters from a string in TypeScript

1 Answer

0 votes
function removeNonASCII(input: string): string {
    return input.replace(/[^\x00-\x7F]/g, '');
}

const input = "©€ABC£µ¥xyz!® 123 こんにちは";
const filtered: string = removeNonASCII(input);

console.log(filtered);


   
/*
run:
   
"ABCxyz! 123 "
   
*/

 



answered Jun 13, 2025 by avibootz
...