将下面的引号替换
<div class="outer" style="border:#ff0000 2px dotted; height:100px; width:100px; background-color:#999999;">替换结果:
<div class=<span class="red">"outer"</span> style=<span class="red">"border:#ff0000 2px dotted; height:100px; width:100px; background-color:#999999;"</span>>
引号前是一种值,引号后是一种值。

解决方案 »

  1.   

    捕获 替换
    查阅js的正则API
      

  2.   


    var str='<div class="outer" style="border:#ff0000 2px dotted; height:100px; width:100px; background-color:#999999;"> ';
    alert(str.replace(/(\"[^"]*\")/g,"<span class=\"red\">$1</span>"));
      

  3.   


      var str = '<div class="outer" style="border:#ff0000 2px dotted; height:100px; width:100px; background-color:#999999;">';
          var re = new RegExp(/(\".*?\")/g);
          
         var newStr = str.replace(re,"<span class=\"red\">$1</span>");楼主试试吧~~