Skip to content

Instantly share code, notes, and snippets.

@darkfe
Last active December 19, 2015 05:49
Show Gist options
  • Save darkfe/5907074 to your computer and use it in GitHub Desktop.
Save darkfe/5907074 to your computer and use it in GitHub Desktop.
删除字符串中的html标签
//@vilic
function deleteHtmlTag(htmlStr){
return return htmlStr.replace(/<(script|noscript|style|button)(?:(["'])[\s\S]*\2|[^>])*>[\s\S]+?<\/\1>
/g, "").replace(/<\/?[a-z]+(?:(["'])[\s\S]*\1|[^>])*>/g, "");
}
function deleteHtmlTag(htmlStr){
return htmlStr
//先删除<x>...</x>类的标签
.replace(/<(script|style|button|noscript)(?:[^"'<>]|'(?:\\.|(?:[^']))*'|"(?:\\.|(?:[^"]))*")*>[\S\s]*?<\/\1>/g,'')
//再删除<x>或者</x>类的标签
.replace(/<\/?[\w:]+(?:[^"'<>]|'(?:\\.|(?:[^']))*'|"(?:\\.|(?:[^"]))*")*>/g,'');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment