2016-02-25 34 views
0

我使用this庫這一行文字preg_match_all中的%符號會做什麼?

#asdfasdf #日本語 スペース @漢字 #日本語 あ http://url file:///url「おくむら」最高ー!… 

的,它給了我正確的價值觀

#asdfasdf #日本語 

但在代碼中有%regex

'%(\A#(\w|(\p{L}\p{M}?)|-)+\b)|((?<=\s)#(\w|(\p{L}\p{M}?)|-)+\b)|((?<=\[)#.+?(?=\]))%u' 

這說明什麼百分號呢?

在iOS中,它沒有像這樣的百分號。

"(\\A#(\\w|(\\p{L}\\p{M}?)|-)+\\b)|((?<=\\s)#(\\w|(\\p{L}\\p{M}?)|-)+\\b)|((?<=\\[)#.+?(?=\\]))" 

在PHP它給我的錯誤:preg_match_all(): Unknown modifier '|'

這是什麼百分號呢?

+1

什麼,這是正則表達式從其他選項分隔符。它們在'preg_ *'庫中是必需的,參見http://php.net/manual/en/regexp.reference.delimiters.php – jeroen

+0

* PHP:[pattern syntax](http://php.net/manual/ en/reference.pcre.pattern.syntax.php)*鏈接到相關文檔,* Delimiters *是第二個要點。 –

回答

0

沒什麼,它是分隔正則表達式從其他選項的分隔符。它們在preg_*庫中是必需的,請參閱http://php.net/manual/en/regexp.reference.delimiters.php

請注意,如果你沒有在你的正則表達式使用%,該(...)將被用作分隔符,導致一個錯誤,當你需要在你的正則表達式使用它們本身,你不要逃避它們。

這是發生在這裏,你的情況:

(\\A#(\\w|(\\p{L}\\p{M}?)| 
         ^Here the regex engine thinks you are closing the expression 
+1

謝謝。 分隔符 – matar