2016-02-25 30 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