构造\ H,\V和\ N是什么意思? [英] What do the constructs \H, \V and \N mean?
问题描述
以下结构没有很好的文档记录,但它们的确适用于PHP的特定版本;这些版本是什么,这些构造是什么以及其他实现支持这个?
The following constructs are not well documented, but they do work as of specific versions of PHP onwards; Which are these versions, what are these constructs and which other implementations support this?
-
\ H
-
\V
-
\ N
\H
\V
\N
此主题是堆栈溢出正则表达式参考。
推荐答案
\H
匹配任何非水平空格的内容。这包括制表符和所有空格分隔符Unicode字符。这与以下相同:
\H
matches anything which aren't horizontal whitespace. This includes tab character and all "space separator" Unicode characters. This is the same as:
[^\h] or
[^\t\p{Zs}]
\V
是 \v
的否定类 - 它被命名为非垂直空白字符并匹配任何不是垂直空白字符的字符,在Unicode标准中被视为换行符,并且将与 \v
匹配,并且与以下内容相同如Perl 5中所介绍的那样:
\V
is the negated class of \v
- It is named "non vertical whitespace character" and matches any characters which aren't a vertical whitespace character of those which are treated as line breaks in the Unicode standard and would be matched by \v
, and is the same as the following as introduced in Perl 5:
[^\v] or
[^\n\cK\f\r\x85\x{2028}\x{2029}]
\ N
匹配任何不是换行符的字符 \ n
。简单!
\N
matches any characters which aren't the line feed character \n
. Simple!
[^\n]
\ V +
和 <之间有什么区别? code> \ N + ?感谢 Avinash Raj for ask。
如文档中指定的Perl 5.10, \V
与 相同[^ \ n\cK\f\r\ x85 \ x {2028} \ x {2029}]
且不应与 \ n
, 中的任何一个匹配\ r
或 \f
,以及 Ctrl +(控制字符)
(* nix), 0x85
, 0x2028
和 0x2029
。
What's the difference between \V+
and \N+
?Thanks to Avinash Raj for asking.
As Perl 5.10 specified in the documentation, \V
is the same as [^\n\cK\f\r\x85\x{2028}\x{2029}]
and shouldn't match any of \n
, \r
or \f
, as well as Ctrl+(Control char)
(*nix), 0x85
, 0x2028
and 0x2029
.
这些角色类很方便当您想要匹配水平文本中的所有内容时非常有效 - \V +
- 或者只是消费整个段落 - \ N +
- 在其他各种用例中。
These character classes are handy and incredibly effective for when you want to match everything within the horizontal text - \V+
- or simply consuming an entire paragraph - \N+
- among various other use cases.
以下实现支持 \H
, \V
和 \N
:
- Perl 5.10
- PCRE 7.2
- PHP程序员可能找出哪些版本支持这些结构的差异。当他们来自Perl 5时,必须设置PCRE版本;您可以使用
phpinfo()
。默认情况下,PHP 5.2.2可以。 - Java 8
java.util.regex.Pattern
支持\H
和\V
构造已添加为实施\h
,<$ c $的一部分c> \v ,这是不适用于Java 7 ,但尚不支持\N
。 使用JDK8u25进行测试。
- Perl 5.10
- PCRE 7.2
- PHP programmers may find a discrepancy over which versions supports these constructs. As they came from Perl 5, one has to set the PCRE version instead; You can check this using
phpinfo()
. By default, PHP 5.2.2 does. - Java 8
java.util.regex.Pattern
support for\H
and\V
constructs has been added as part of implementing\h
,\v
, which was not true for Java 7, however\N
is not yet supported. Tested with JDK8u25.
这篇关于构造\ H,\V和\ N是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!