日期:2014-05-16  浏览次数:20371 次

求替换内容中的部分格式的方法,在线等待!
想用正则表达式替换内容中含有如下格式的字符
width= "90 "   或者 width=100   或者 width= '210 '
height= "100 "   或者   height=200   或者 width= '300 '

在线等待,有结果马上结贴,谢谢



------解决方案--------------------
<textarea id= "wc " style= "width:300px; height:300px; "> 想用正则表达式替换内容中含有如下格式的字符
width= "90 " 或者 width=100 或者 width= '210 '
height= "100 " 或者 height=200 或者 width= '300 ' </textarea>
<script type= "text/javascript ">
window.onload = function () {
var pa = /[ ]?(?:height|width)=(?: '[^ ']+ '| "[^ "]+ "|\d+)/gi
, wc = document.getElementById( "wc ");
wc.value = wc.value.replace(pa, " ");
};
</script>
------解决方案--------------------
:D
怎么没人回答。。你的需求也没说明白,替换成空的话就是上面的CODE即可。。如果你还想在严紧的话说明下具体需求。
------解决方案--------------------
var m= ' <tr width= "90 " height=100 width=\ '210\ '> '
alert(m.replace(/ (.*?=[\ '\ "]\d+[\ '\ "])/g, " "))
------解决方案--------------------
<script language=javascript>
var str= 'asdads width= "90 " 或者 width=100 或者 width=\ '210\ ' height= "100 " 或者 height=200 或者 width=\ '300\ ' sdfsdf '
re=/((height)|(width))\s*=\s*([ " ']?)\d+\4/ig
var result=str.replace(re, " ")
alert(result)
</script>