2011-03-29 18 views

回答

3

pcrepattern specifications頁:

通用字符類型

\s  any white space character 

爲了與Perl兼容,\ s沒有用來匹配VT字符 (代碼11),這使得它與POSIX「空間」類不同。 但是,Perl在版本5.18中添加了VT,而PCRE在 版本8.34中也加上了。默認的\ s字符現在是HT(9),LF(10),VT (11),FF(12),CR(13)和空格(32),它們被定義爲白色 空間中的「C 「語言環境。如果匹配正在發生,特定區域設置 ,此列表可能會有所不同。例如,在某些語言環境中, 「不間斷空格」字符(\ xA0)被識別爲空格, ,而在其他字符中,VT字符不是。

所以\s將匹配5個字符,再加上更多的取決於:

  1. PCRE庫版本
  2. 區域設置

This test跨PHP的各種版本的preg_match的結果進行比較。

+2

我也到了這裏尋找名單。但頁面可能已經改變。下面的列表: 空白由\ S匹配裝置只有這些5個字符: 9 = 0×09 =水平製表, 10 =的0x0A =換行, 12 = 0x0C =形式飼料, 13 = 0X0D =回車, 32 = 0x20 =空格, http://www.php.net/manual/en/regexp.reference.escape.php – 2013-10-11 14:44:36

3

PHP有\h僅用於水平空白字符:http://www.php.net/manual/en/regexp.reference.escape.php

根據http://www.pcre.org/pcre.txt

對於用Perl兼容性,\ s不所述VT字符(代碼 11)相匹配。這使得它不同於POSIX「空間」類。字符是HT(9),LF(10),FF(12),CR(13)和空格(32)。如果 「使用語言環境;」包含在Perl腳本中,\ s可以匹配VT字符。在PCRE中,它永遠不會。

所以如果「垂直空間」是指垂直標籤,答案是否定的。

 
The sequences \h, \H, \v, and \V are features that were added to Perl 
at release 5.10. In contrast to the other sequences, which match only 
ASCII characters by default, these always match certain high-valued 
codepoints in UTF-8 mode, whether or not PCRE_UCP is set. 

The horizontal space characters are: 

     U+0009  Horizontal tab 
     U+0020  Space 
     U+00A0  Non-break space 
     U+1680  Ogham space mark 
     U+180E  Mongolian vowel separator 
     U+2000  En quad 
     U+2001  Em quad 
     U+2002  En space 
     U+2003  Em space 
     U+2004  Three-per-em space 
     U+2005  Four-per-em space 
     U+2006  Six-per-em space 
     U+2007  Figure space 
     U+2008  Punctuation space 
     U+2009  Thin space 
     U+200A  Hair space 
     U+202F  Narrow no-break space 
     U+205F  Medium mathematical space 
     U+3000  Ideographic space 

The vertical space characters are: 

     U+000A  Linefeed 
     U+000B  Vertical tab 
     U+000C  Formfeed 
     U+000D  Carriage return 
     U+0085  Next line 
     U+2028  Line separator 
     U+2029  Paragraph separator 
+0

但是,這並不表示任何'\ s'是否包含它... – 2011-03-29 11:22:58

+0

那麼,http://www.pcre.org/pcre.txt表示它不匹配垂直選項卡 - 我不'不知道什麼是垂直空間。 – Kobi 2011-03-29 11:31:04

+0

什麼是水平空白字符? – Stephan 2011-03-29 11:32:50

1

http://www.pcre.org/pcre.txt

\ S任何字符\ p {Z}匹配, 加HT,LF,FF,CR

+4

正確引用時,這取決於編譯時設置。 PHP在該代碼周圍使用'#ifdef PCRE_UCP'。它不應該被依賴。 – mario 2011-03-29 11:35:12