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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6239185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 14:58:46  来源:igfitidea点击:

What does the regex string "\\p{Cntrl}" match in Java?

javaregex

提问by Wes Nolte

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. Does anyone know?

我认为它匹配所有控制字符(不确定“全部”可能是什么),但我不能确定,除了 Perl 论坛中的一些思考之外,我也无法在任何文档中找到它。有人知道吗?

回答by aioobe

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 articleon control characters lists each character and what it's used for if you're interested.

如果您感兴趣,维基百科关于控制字符的文章列出了每个字符及其用途。

回答by geekosaur

\p{name}matches a Unicode character class; consult the appropriate Unicode spec to see what code points are in the class. Hereis a discussion specific to the Java regex engine (Cntrlbeing one of the examples), although the same thing applies to many other regex engines.

\p{name}匹配一个 Unicode 字符类;查阅适当的 Unicode 规范以查看类中的代码点。 这里是针对 Java regex 引擎的讨论(Cntrl作为示例之一),尽管同样的事情适用于许多其他 regex 引擎。