标签:
var str = "<sup><div class=\"he‘s\"/></sup><span id=\"cs\"/>"; function removeCloseTag(str) { var regCloseTag = /<[^>]+\/>/, regTagName = /[^<][^\s]+/, tmp, tagName; while((tmp = str.match(regCloseTag)) && tmp.length > 0){ tagName = tmp[0].match(regTagName); str = str.replace(/\/>/, ‘></‘+tagName+‘>‘); } return str; } var res = removeCloseTag(str); //<sup><div class="he‘s"></div></sup><span id="cs"></span>
(正则表达式应用) 替换自闭合标签(self-closing tag)的method
标签:
原文地址:http://www.cnblogs.com/gentlemint/p/5544202.html