Skip to content

Instantly share code, notes, and snippets.

@fjeldstad
Last active October 13, 2021 17:09
Show Gist options
  • Save fjeldstad/ba90ccee0cde981655708ce1054f2a7a to your computer and use it in GitHub Desktop.
Save fjeldstad/ba90ccee0cde981655708ce1054f2a7a to your computer and use it in GitHub Desktop.
Removing all (or perhaps just "common") non-printable Unicode characters - except line breaks - from a string in JavaScript. (Adaptation of http://stackoverflow.com/questions/21284228/removing-control-characters-in-utf-8-string?lq=1)
const trimmed = problematicString.replace(/[\x00-\x09\x0B-\x0C\x0E-\x1F\x7F-\x9F]/g, '');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment