8 examples of 'regex remove html tags' in JavaScript

Every line of 'regex remove html tags' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
405function removeHTMLTags(str) {
406 debug(`\tremoveHTMLTags BEFORE: ${str}`);
407 const replStr = str
408 .replace(tagsToRemoveRegex, '')
409 .replace(classToRemoveRegex, '');
410 debug(`\tremoveHTMLTags AFTER: ${replStr}`);
411 return replStr;
412}
323function removeHTMLTags(str){
324 str = str.replace(/&(lt|gt);/g, function (strMatch, p1) {
325 return (p1 === "lt") ? "<" : ">";
326 });
327 var strTagStrippedText = str.replace(/<\/?[^>]+(>|$)/g, "");
328 strTagStrippedText = strTagStrippedText.replace(/ /g,"");
329 return strTagStrippedText;
330}
397function _sanitizeHtml(html: string): string {
398 return html.replace(/\<\s*script/gi, '');
399}
329function removeHTMLTag(str) {
330 str = str.replace(/<\/?[^>]*>/g, ''); //去除HTML tag
331 str = str.replace(/[ | ]*\n/g, '\n'); //去除行尾空白
332 //str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
333 str = str.replace(/ /ig, ''); //去掉
334 return str;
335}
194static removeSpacesInsideTags_(htmlString) {
195 htmlString = htmlString.replace(html.Patterns.TAG_END_SPACES, '$1$2');
196 htmlString = htmlString.replace(html.Patterns.TAG_QUOTE_SPACES, '=$1$2$3');
197 return htmlString;
198}
209function cleanHtml (html) {
210 return html.replace(/>\s+<').trim()
211}
3function stripTags(str) {
4 return str.replace(/(<([^>]+)>)/ig, "");
5}
198removeSelf(text, self) {
199 const reg = new RegExp("<" + self + "(.*?)>", "g");
200 return text.replace(reg, "");
201}

Related snippets