Regular expression for all printable characters in JavaScript

If you want to match all printable characters in the UTF-8 set (as indicated by your comment on Aug 21), you’re going to have a hard time doing this yourself. JavaScript’s native regexes have abysmal Unicode support. But you can use XRegExp with the regex ^\P{C}*$.

If you only want to match those few ASCII letters you mentioned in the edit to your post from Aug 22, then the regex is trivial:

/^[a-z0-9!"#$%&'()*+,.\/:;<=>?@\[\] ^_`{|}~-]*$/i

Leave a Comment