Regular expression for all printable characters in JavaScript

前端 未结 4 1698
时光说笑
时光说笑 2020-11-27 20:33

Looking for a regular expression for that validates all printable characters. The regex needs to be used in JavaScript only. I have gone through this post but it mostly talk

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 20:48

    For non-unicode use regex pattern ^[^\x00-\x1F\x80-\x9F]+$


    If you want to work with unicode, first read Javascript + Unicode regexes.

    I would suggest then to use regex pattern ^[^\p{Cc}\p{Cf}\p{Zl}\p{Zp}]*$

    • \p{Cc} or \p{Control}: an ASCII 0x00..0x1F or Latin-1 0x80..0x9F control character.
    • \p{Cf} or \p{Format}: invisible formatting indicator.
    • \p{Zl} or \p{Line_Separator}: line separator character U+2028.
    • \p{Zp} or \p{Paragraph_Separator}: paragraph separator character U+2029.

    For more information see http://www.regular-expressions.info/unicode.html

提交回复
热议问题