(正则表达式应用) 替换自闭合标签(self-closing tag)的method

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>
上一篇:AMD and CMD are dead之KMD规范


下一篇:Ubuntu12.04安装64位系统出现编译错误error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or dir