正则表达式模式“[\\P{L}]+”在 Java 中是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36312464/
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-11-03 01:15:31  来源:igfitidea点击:

What does regex pattern "[\\P{L}]+" mean in Java?

javaregex

提问by Sayakiss

Code:

代码:

Arrays.asList("AAAA DDDD, DDDD".split("[\P{L}]+")).forEach(System.out::println);

Output:

输出:

AAAA
DDDD
DDDD

Please notice it's P{L}instead of p{L}(which means letters). I googled it but find nothing. So could any one give me some hint about that?

请注意它是P{L}而不是p{L}(这意味着字母)。我用谷歌搜索但一无所获。那么任何人都可以给我一些提示吗?

回答by Tunaki

You can find the explanation in PatternJavadoc:

您可以在PatternJavadoc 中找到解释:

Unicode scripts, blocks, categories and binary properties are written with the \pand \Pconstructs as in Perl. \p{prop}matches if the input has the property prop, while \P{prop}does not match if the input has that property.

Unicode 脚本、块、类别和二进制属性是用Perl 中的\p\P构造编写的。\p{prop}如果输入具有属性 prop 则\P{prop}匹配,如果输入具有该属性则不匹配。

So it's the opposite of \p.

所以它的反义词是\p

回答by Mena

Simple: it's the opposite of \\p{L}.

很简单:它与\\p{L}.

Essentially all "non-letters".

基本上都是“非字母”。

I couldn't find an exactreference in the API, but you can infer the suggestion from the behavior or, say, \\svs \\S(which isdocumented there).

我无法找到一个准确的参照API,但你可以从行为推断或建议,说,\\sVS \\S(这记录都在这里)。

Edit(credit to Tunakifor having eyes)

编辑感谢 Tunaki有眼睛)

This is actually suggested by the following statement in the documentation:

这实际上是由文档中的以下声明所建议的:

Unicode blocks and categories are written with the \p and \P constructs as in Perl.

Unicode 块和类别是用 \p 和 \P 结构编写的,就像在 Perl 中一样。