请教个js正则问题 如何去html内容中的空格
比如:
<html style=" xxx:xxx" ><div style=" xxx:xxx" class="xxxxx">     ssss  ss ss  ss      </div></html>
让其变成
<html style=" xxx:xxx" ><div style=" xxx:xxx" class="xxxxx">ssssssssss</div></html>
或者文字前面的空格不去
<html style=" xxx:xxx" ><div style=" xxx:xxx" class="xxxxx">     ssssssssss</div></html>
不要去掉“html style”中的空格(标签中的属性的空格不要去掉)!
谢谢!

解决方案 »

  1.   

    <html style=" xxx:xxx" ><div style=" xxx:xxx" class="xxxxx"> ssss ss ss ss </div></html>是一个文本
      

  2.   

    vat s=$(".xxxxx").text(); 
    $(".xxxxx").text()=s.replace(/\s*/g, "");  
      

  3.   

    谢谢大家了,可能我没说清楚!
    <html style=" xxx:xxx" ><div style=" xxx:xxx" class="xxxxx"> ssss ss <a style ="xxx" class="xxx" href="http://baidu.com" >aa  aaa</>ss ss </div></html>这段是从文本编辑器取出的一段文字!当然我也想试过把它处理成dom取文本处理,但对于无限级嵌套处理很麻烦还是直接用正则简单!请问正则怎么写?
      

  4.   

    '<html style=" xxx:xxx" ><div style=" xxx:xxx" class="xxxxx"> ssss ss ss ss </div></html>'.replace(/(?=[^>]*(?=<))\s+/g, "")
      

  5.   


    var html="<html style=\" xxx:xxx\" ><div style=\" xxx:xxx\" class=\"xxxxx\"> ssss ss ss ss </div></html>";
    alert(html);
    html = html.replace(/\s+([^<>]+)(?=<)/g, function (m) { 
    return m.replace(/\s+/g,'');
    });
    alert(html);
      

  6.   

    若文本中包含&nbsp;这样的空格要怎么去掉?