文字列内のショートコードを照合したかったので、ここから次の正規表現を見つけました。正常に動作します。しかし、私はそれがどのように機能するかを学びたいです。
誰かplzがこの正規表現のコンポーネントとそれがショートコードとどのように一致するかを私に説明できますか?
preg_match_all('%(?<=\[shortcode\]).*?(?=\[/shortcode\])%s',$content, $result, PREG_PATTERN_ORDER);
正規表現を説明するツールがあります。
あなたの例:
NODE EXPLANATION
----------------------------------------------------------------------
(?<= look behind to see if there is:
----------------------------------------------------------------------
\[ '['
----------------------------------------------------------------------
shortcode 'shortcode'
----------------------------------------------------------------------
\] ']'
----------------------------------------------------------------------
) end of look-behind
----------------------------------------------------------------------
.*? any character (0 or more times
(matching the least amount possible)
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
\[ '['
----------------------------------------------------------------------
/shortcode '/shortcode'
----------------------------------------------------------------------
\] ']'
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
アサーションの詳細については、http://www.regular-expressions.info/lookaround.htmlを参照してください。