比方說,我有這樣的字符串:PHP - 的preg_replace有多個匹配
$text = "<object>item_id1a2b3</object>xxx<object>item_id4c5d6</object>"
我想將其轉換爲: %ITEM:1a2b3xxx%ITEM:4c5d6
下面是我得到了什麼:
$text = preg_replace("/<object.*item_id([a-zA-Z0-9]+).*<\/object/","%ITEM:$1",$text);
這是不完全正確的,因爲搜索是貪婪的。
想法?
謝謝!