正则表达式的所有​​可打印字符 [英] Regex for all PRINTABLE characters

查看:1109
本文介绍了正则表达式的所有​​可打印字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有像\一个特殊的正则表达式语句W¯¯这表示所有可打印字符?我想验证一个字符串只包含一个字符,可以打印 - 即不包含像\ B(钟),或者为null,等任何键盘上是好的,所以是UTF字符。

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. does not contain ASCII control characters like \b (bell), or null, etc. Anything on the keyboard is fine, and so are UTF chars.

如果没有特别的声明,我怎么能在一个正则表达式指定此?

If there isn't a special statement, how can I specify this in a regex?

推荐答案

好吧,如果你Google一下,你会发现一些答案的时候了。有一个POSIX字符类指定 [:打印:] 应该匹配可打印字符, [:CNTRL:] 为控制字符。请注意,这些匹配codeS整个ASCII表,所以他们可能不适合用于匹配其它编码

Well, if you Google it you'll find some answers right away. 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.

如果做不到这一点,前pression [\ x00- \ X1F] 将匹配通过ASCII控制字符,虽然再次,这可能是打印在其他编码

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

这篇关于正则表达式的所有​​可打印字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆