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

1 Answer

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

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

console.log("Filtered string:", filtered);


   
/*
run:
   
Filtered string: ABCxyz! 123 
   
*/

 



answered Jun 13, 2025 by avibootz
...