以下两种方法都能达到效果
但用正则可能对资源有些浪费
[php]
<?php
$str='/ewebeditor/uploadfile/20081222093646223.jpg|../ewebeditor/uploadfile/20081222093649254.gif|ewebeditor/uploadfile/20081222093649254.gif';
$arr = explode('|', $str);
print_r($arr);

preg_match_all('/.+?(?=\||$)/', $str, $arr2);
print_r($arr2);
?>
[/php]

解决方案 »

  1.   

    你竟然还有个随机取的需求,这明显不是正则可以一步到位的问题。用explode先按|转换为数组,然后用array_rand随机从数组里取数据吧
      

  2.   

    2楼是正确的,不过有个问题。
    preg_match('/.+?(?=\||$)/',$allimages,$matches);使用上面的语句OK了,这个“\||$”应该是查找以“|”结束的地方,为什么要两个“|”?
    另外不在有随机要求,现在是可否让取出的值不包括“|”符号呢?
      

  3.   

    \|    |      $
    |     或   结束
    不像出现可以如下:<?php
    $str='/ewebeditor/uploadfile/20081222093646223.jpg|../ewebeditor/uploadfile/20081222093649254.gif|ewebeditor/uploadfile/20081222093649254.gif';
    //$arr = explode('|', $str);
    //print_r($arr);preg_match_all('/(.+?)(?:\||$)/', $str, $arr2);
    print_r($arr2[1]);
    ?>