preg_match_all 中的 % 符号有什么作用?
what does % sign do in preg_match_all?
我正在使用 this 库和这行文本
#asdfasdf #日本語 スペース @漢字 #日本語 あ http://url file:///url「おくむら」最高ー!…
它给了我正确的价值观
#asdfasdf #日本語
但是在代码中有 %
in 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 '|'
这个百分号有什么作用?
没有,它是分隔正则表达式和附加选项的分隔符。 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
我正在使用 this 库和这行文本
#asdfasdf #日本語 スペース @漢字 #日本語 あ http://url file:///url「おくむら」最高ー!…
它给了我正确的价值观
#asdfasdf #日本語
但是在代码中有 %
in 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 '|'
这个百分号有什么作用?
没有,它是分隔正则表达式和附加选项的分隔符。 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