日期:2014-05-16  浏览次数:20383 次

请问正则表达式怎么写?
{dede:pagestyle maxwidth='' pagepicnum='' ddmaxwidth='' row='' col='' value=''/} {dede:img ddimg='/uploads/allimg/120507/1-12050G32F7.jpg' text='' width='500' height='374'} /uploads/allimg/120507/1-12050G32F7.jpg {/dede:img} {dede:img ddimg='/uploads/allimg/120507/1-12050G32F8.jpg' text='' width='500' height='374'}/uploads/allimg/120507/1-12050G32F8.jpg{/dede:img}

获取内容一: /uploads/allimg/120507/1-12050G32F7.jpg 

获取内容二: /uploads/allimg/120507/1-12050G32F8.jpg

请问用正则怎么写?
我要如何才能获取 图片地址啊

------解决方案--------------------
JScript code
var str="{dede:pagestyle maxwidth='' pagepicnum='' ddmaxwidth='' row='' col='' value=''/} {dede:img ddimg='/uploads/allimg/120507/1-12050G32F7.jpg' text='' width='500' height='374'} /uploads/allimg/120507/1-12050G32F7.jpg {/dede:img} {dede:img ddimg='/uploads/allimg/120507/1-12050G32F8.jpg' text='' width='500' height='374'}/uploads/allimg/120507/1-12050G32F8.jpg{/dede:img}";
    var p=/\{dede:img[^\}]*\}(.*?)\{\/dede:img\}/g;
    var arr=[];
    var m=null;
  while(m=p.exec(str)){
         arr.push(RegExp.$1);  
  }    
alert(arr);

------解决方案--------------------
探讨

\{dede:img\s*ddimg='[^']+'[^}]*\}(.*?)\{/dede:img\}
取第1个分组
或者
\{(dede:img)\s*ddimg='[^']+'[^}]*\}(.*?)\{/\1\}
取第2个分组