2013-07-30 50 views
-1

我有一個問題得到我的正則表達式模式來標識一個選項卡。這裏是我的代碼:正則表達式不計算標籤

$strings = array(
    ' abc', 
    '\tabc', 
    '^abc' 
); 
$count = 0; 
foreach($strings as $string){ 
    if (preg_match('/[\s\t\'^£$%&*()}{@#~?><>,|=_+¬-]/', $string)){ 
     echo $string . "<br/>"; 
    } 
} 

它只佔2項,abc^abc,不\tabc

+1

''\ tabc''不包含tab,'「\ tabc」'。 – str

+1

請注意,\ s是一個空格字符,可以包含\ t,具體取決於語言。它在PHP中。 –

+0

關於@ Phil的回答,如果你想匹配''\ t'',那麼你可以使用'\\\\ t' – 2013-07-30 00:26:41

回答

1

對於PHP解釋的字符串(如\t\r\n)控制字符,你需要使用雙引號,例如

$strings[] = "\tabc";