Regex for all PRINTABLE characters

前端 未结 6 1353
囚心锁ツ
囚心锁ツ 2020-12-11 01:09

Is there a special regex statement like \\w that denotes all printable characters? I\'d like to validate that a string only contains a character that can be printed--i.e. do

6条回答
  •  没有蜡笔的小新
    2020-12-11 01:13

    There is a POSIX character class designation [:print:] that should match printable characters, and [:cntrl:] for control characters. Note that these match codes throughout the ASCII table, so they might not be suitable for matching other encodings.

    Failing that, the expression [\x00-\x1f] will match through the ASCII control characters, although again, these could be printable in other encodings.

提交回复
热议问题