本帖最后由 sunxingtao 于 2011-10-24 17:23:03 编辑

解决方案 »

  1.   

    你可通过stringObj.indexOf()结合substring来完成,很简单的,你了解下这两个函数吧
      

  2.   


    var re = /^LETTER-SPACING\:\s*(\-?\d)pt$/g;
    var str = 'LETTER-SPACING: -5pt';
    str = str.replace(re,function(){
       return "LETTER-SPACING:" + 2*parseInt(arguments[1]) + "pt"
    });
    alert(str);
      

  3.   

    楼上正解
    var str = '<P style="TEXT-ALIGN: center; LINE-HEIGHT: 55pt; mso-line-height-rule: exactly" class=MsoNormal align=center><SPAN style="FONT-FAMILY: 华文新魏; LETTER-SPACING: -5pt; COLOR: red; FONT-SIZE: 43pt; mso-font-kerning: 5.0pt">能在自己的航海图上标注上之前成功的船队的航行路线<SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></SPAN></P>'
    var rule = /LETTER-SPACING\:\s*(\-?\d)pt/g;
    rst = str.replace(rule,function(){
           alert(arguments[1]);
           return "LETTER-SPACING:" + 2*parseInt(arguments[1]) + "pt"
    });
    alert(rst);
      

  4.   

    正则匹配倒是没问题...就是计算方法上有问题...算不出正常数值...
    javascript: 
    var strObj='<P style="TEXT-ALIGN: center; LINE-HEIGHT: 55pt; mso-line-height-rule: exactly" class=MsoNormal align=center><SPAN style="FONT-FAMILY: 华文新魏; LETTER-SPACING: -5pt; COLOR: red; FONT-SIZE: 43pt; mso-font-kerning: 5.0pt">能在自己的航海图上标注上之前成功的船队的航行路线<SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></SPAN></P>';
    alert(strObj.replace(/(LETTER-SPACING\:\s*[+-]?)(\d{1,})pt\;/gi,'$1'+(Number('$2')*2)+'pt\;')); void(0);
      

  5.   

    var strObj='<P style="TEXT-ALIGN: center; LINE-HEIGHT: 55pt; mso-line-height-rule: exactly" class=MsoNormal align=center><SPAN style="FONT-FAMILY: 华文新魏; LETTER-SPACING: -5pt; COLOR: red; FONT-SIZE: 43pt; mso-font-kerning: 5.0pt">能在自己的航海图上标注上之前成功的船队的航行路线<SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></SPAN></P>';
    alert(strObj.replace(/(LETTER-SPACING\:\s*[+-]?)(\d{1,})pt/gi,function(){ return arguments[1]+parseInt(arguments[2])*2 + 'pt'; })); 
      

  6.   

    '$1'+(Number('$2')*2)+'pt\;'))这样做貌似Number没有把$2当做5处理而是当做$2的字符串处理?
      

  7.   

    '$1'+(Number('$2')*2)+'pt\;'这样做会让Number直接去转换$2造成转换失败这个应该是js替换的时候内部机制的问题
      

  8.   


    var str = '<P style="TEXT-ALIGN: center; LINE-HEIGHT: 55pt; mso-line-height-rule: exactly" class=MsoNormal align=center><SPAN style="FONT-FAMILY: 华文新魏; LETTER-SPACING: -5pt; COLOR: red; FONT-SIZE: 43pt; mso-font-kerning: 5.0pt">能在自己的航海图上标注上之前成功的船队的航行路线<SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></SPAN></P>';
    var str1 = str.replace(/LETTER-SPACING:\s*(-?\d*)/gi,function(a,p1){return 'LETTER-SPACING:'+Number(p1)*2});
    alert(str1);抄袭了一下
      

  9.   

    谢谢lijpwsw啊...受教了...没用过arguments[1]这种...我以前一直以为只有vbs里有arguments呢...= =!!
      

  10.   

    parseInt是取整吧...考虑到有小数的可能...我觉得Number()好点...改了一下正则...
    javascript:  
    var strObj='<P style="TEXT-ALIGN: center; LINE-HEIGHT: 55pt; mso-line-height-rule: exactly" class=MsoNormal align=center><SPAN style="FONT-FAMILY: 华文新魏; LETTER-SPACING: -5.2pt; COLOR: red; FONT-SIZE: 43pt; mso-font-kerning: 5.0pt">能在自己的航海图上标注上之前成功的船队的航行路线<SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></SPAN></P>';
    alert(strObj.replace(/(LETTER-SPACING\:\s*[+-]?)([\d\.]{1,})pt\;/gi,function(){return arguments[1]+(Number(arguments[2])*2)+'pt\;';})); void(0);
      

  11.   


    对不起您了   分太少
    而且您那个确实不好用,要不您亲自用长的字符串试下
    var re = /^LETTER-SPACING\:\s*(\-?\d)pt$/g;
    var str='<P style="TEXT-ALIGN: center; LINE-HEIGHT: 55pt; mso-line-height-rule: exactly" class=MsoNormal align=center><SPAN style="FONT-FAMILY: 华文新魏; LETTER-SPACING: 5pt; COLOR: red; FONT-SIZE: 43pt; mso-font-kerning: 5.0pt">能在自己的航海图上标注上之前成功的船队的航行路线<SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></SPAN></P>';
    str = str.replace(re,function(){
       return "LETTER-SPACING:" + 2*parseInt(arguments[1]) + "pt"
    });
    alert(str);