<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>
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>
怎么没人回答。。你的需求也没说明白,替换成空的话就是上面的CODE即可。。如果你还想在严紧的话说明下具体需求。
alert(m.replace(/ (.*?=[\'\"]\d+[\'\"])/g," "))
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>