<script language=javascript>
var str="<font color=red>test1</font>"
re=/(color=)(red)/g
str=str.replace(re,"$1#ffffff")
alert(str)
</script>

解决方案 »

  1.   

    <script language=javascript>
    var str="<font color=red>test1</font><b>test2</b>"
    re=/(color=)(red)/g
    str=str.replace(re,"$1#ffffff")
    str=str.replace(/(<b.*?>)(.*?)<\/b>/i,"<font color=#ffffff>$2<\/font>")
    alert(str)
    </script>
      

  2.   

    还有一种情况,请您帮忙字符串:<font color=red>test1</font><b>test2</b><a href=#>test3</a>
    替换为:<font color=#ffffff>test1</font><font color=#ffffff>test2</font><font color=#ffffff>test3</font>
      

  3.   

    str=str.replace(/<a[^>]*>([\s\S]+?)<\/a>/i,"<font color=#ffffff>$1<\/font>");
    飘过
      

  4.   

    <script language=javascript>
    var str="<font color=red>test1</font><b>test2</b><a href=#>test3</a>"
    re=/(color=)(red)/gi;
    str=str.replace(re, "$1#ffffff");
    str=str.replace(/<(b|a)[^>]*>([\S\s]+?)<\/\1>/gi,"<font color=#ffffff>$2<\/font>");
    alert(str)
    </script>
    我那个是要加到hbhbhbhbhb1021写的后面的
    直接改了下,这个简单。
      

  5.   

    谢谢
    str.replace(/<.+?>(.+?)<\/.+?>/ig,'<font color=green>$1</font>')
      

  6.   

    这个好象不太好的说。。
    如果先匹配所有开头结尾(不支持同类欠套比如<a><a></a></a>)的话
    那么<(?!\/)([\S]+?)(\s[^>]+)?>([\S\s]+?)<\/\1>