简体   繁体   English

Java 中的正则表达式字符串“\\p{Cntrl}”匹配什么?

[英]What does the regex string “\\p{Cntrl}” match in Java?

I think it's matching all control characters (not sure what "all" might be) but I can't be certain, nor can I find it in any documentation other than some musings in a Perl forum.我认为它匹配所有控制字符(不确定“全部”可能是什么),但我不能确定,除了 Perl 论坛中的一些思考之外,我也无法在任何文档中找到它。 Does anyone know?有人知道吗?

From the documentation of Pattern :Pattern的文档中:

\p{Cntrl} A control character: [\x00-\x1F\x7F] \p{Cntrl}控制字符: [\x00-\x1F\x7F]

That is, it matches any character with hexadecimal value 00 through 1F or 7F.也就是说,它匹配十六进制值 00 到 1F 或 7F 的任何字符。

The Wikipedia article on control characters lists each character and what it's used for if you're interested.有关控制字符的Wikipedia 文章列出了每个字符及其用途(如果您有兴趣)。

\p{name} matches a Unicode character class; \p{name}匹配一个 Unicode 字符 class; consult the appropriate Unicode spec to see what code points are in the class.请查阅相应的 Unicode 规范以查看 class 中的代码点。 Here is a discussion specific to the Java regex engine ( Cntrl being one of the examples Any ASCII control character in the range 0-127. This effectively means characters 0-31 and 127. ), although the same thing applies to many other regex engines. 是针对 Java 正则表达式引擎的讨论( Cntrl是示例之一Any ASCII control character in the range 0-127. This effectively means characters 0-31 and 127. ),尽管同样的事情适用于许多其他正则表达式引擎.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM