Skip to main content

JavaScript function to remove non-printable ASCII characters. Uses a regular expression to remove non-printable ASCII characters.

/**
 * Removes non-printable ASCII characters.
 *
 * @param {string} str
 * @return {string}
 */
const removeNonASCII = str => str.replace(/[^\x20-\x7E]/g, "");

//
// Example Usage:
removeNonASCII("äÄçÇéÉêlorem-ipsumöÖÐþúÚ"); // 'lorem-ipsum'