<script language=javascript>
var str="<font color=red>test1</font>"
re=/(color=)(red)/g
str=str.replace(re,"$1#ffffff")
alert(str)
</script>
var str="<font color=red>test1</font>"
re=/(color=)(red)/g
str=str.replace(re,"$1#ffffff")
alert(str)
</script>
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>
替换为:<font color=#ffffff>test1</font><font color=#ffffff>test2</font><font color=#ffffff>test3</font>
飘过
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写的后面的
直接改了下,这个简单。
str.replace(/<.+?>(.+?)<\/.+?>/ig,'<font color=green>$1</font>')
如果先匹配所有开头结尾(不支持同类欠套比如<a><a></a></a>)的话
那么<(?!\/)([\S]+?)(\s[^>]+)?>([\S\s]+?)<\/\1>