用于字符串的PHP正则表达式preg_match_all

Ibe*_*dia 2 php regex

我有以下字符串:

关键字|标题| HTTP://example.com/

我想使用PHP函数

preg_match_all ( $anchor, $key, $matches, PREG_SET_ORDER) )
Run Code Online (Sandbox Code Playgroud)

目前

$anchor='/([\w\W]*?)\|([\w\W]*)/';
Run Code Online (Sandbox Code Playgroud)

我得到$ matches数组:

Array
(
    [0] => Array
        (
            [0] => keyword|title|http://example.com/
            [1] => keyword
            [2] => title|http://example.com/
        )

)
Run Code Online (Sandbox Code Playgroud)

我想得到

matches[1]=keyword
matches[2]=title
matches[3]=http://example.com
Run Code Online (Sandbox Code Playgroud)

我怎么能修改$ anchor来实现这个目标?

Fel*_*ing 6

最简单的方法是使用explode()而不是正则表达式:

$parts = explode('|', $str);
Run Code Online (Sandbox Code Playgroud)

假设没有任何部件可以包含|.但如果可以的话,正则表达式对你也无济于事.