如题,想用js获取字符串中被"<-","->"括起来的内容。
  如,有字串:str = "<b><-$uinfo.first_name-></b></font> 邀请您参加 <b><font color="#f00000"><-$meetinfo[0].confDesc-></font></b>会议";现在想把$uinfo.first_name,$meetinfo[0].confDesc提取出来放到一个数组中。我js很菜,希望高手能帮帮忙。
这里小弟先谢过了!

解决方案 »

  1.   


    var str = ' <b> <-$uinfo.first_name-> </b> </font> 邀请您参加 <b> <font color="#f00000"> <-$meetinfo[0].confDesc-> </font> </b>会议';
    var reg=/<-(.*?)->/g,res=[],temp;
    while((temp=reg.exec(str))!=null){
        res[res.length]=temp[1];
    }
    alert(res);
    ps:你原有字符串声明不合法,双引号里只能有单引号或者转义
      

  2.   


    谢谢呀!
    我想把<-$uinfo.first_name-> 用其它字符串替换该怎么做呢?比如想用"<div></div>"替换。
      

  3.   


    var str = '<b> <-$uinfo.first_name-> </b> </font> 邀请您参加 <b> <font color="#f00000"> <-$meetinfo[0].confDesc-> </font> </b>会议',
    reg=/<-(.*?)->/g,
    res=str.replace(reg,"<div>$1<div>");
    //res=str.replace(/<-.*?->/g,"<div></div>")//???
    alert(res);