Javascript Regular Expressions Escape HTML Tag

Description

Javascript Regular Expressions Escape HTML Tag



let pieceOfHtml = "<p>This is a <span>paragraph</span></p>";

console.log(pieceOfHtml);//w w  w . ja  v  a 2  s  . c o  m

pieceOfHtml = pieceOfHtml.replace(/</g,"&lt;");
pieceOfHtml = pieceOfHtml.replace(/>/g,"&gt;");

console.log(pieceOfHtml);



PreviousNext

Related