Regex for all PRINTABLE characters

Very late to the party, but this regexp works: /[ -~]/.

How? It matches all characters in the range from space (ASCII DEC 32) to tilde (ASCII DEC 126), which is the range of all printable characters.

If you want to strip non-ASCII characters, you could use something like:

$someString.replace(/[^ -~]/g, '');

NOTE: this is not valid .net code, but an example of regexp usage for those who stumble upon this via search engines later.

Leave a Comment