我有以下字符串:PHP正则表达式preg_match_all字符串
关键字|标题| HTTP://example.com/
我想用PHP函数
preg_match_all ($anchor, $key, $matches, PREG_SET_ORDER))
当前
$anchor='/([\w\W]*?)\|([\w\W]*)/';
我得到$ matches数组:
Array
(
[0] => Array
(
[0] => keyword|title|http://example.com/
[1] => keyword
[2] => title|http://example.com/
)
)
我想获得
matches[1]=keyword
matches[2]=title
matches[3]=http://example.com
我会如何修改$锚实现这一目标?
你只需要在你的正则表达式中增加一个'\ |([\ w \ W] *?)''。 – mario 2011-04-12 21:12:33
谢谢,这工作。最终表达式:$ anchor ='/([\ w \ W] *?)\ |([\ w \ W] *?)\ |([\ w \ W] *)/'; – IberoMedia 2011-04-12 21:52:14