Nodejs HTML Strip stripHtml()

Here you can find the source of stripHtml()

Method Source Code

//Assumption: this is to be written with a regular expression and 
//not processed by the browser, like this example.   
//var div = document.createElement("DIV");
//div.innerHTML = stringWithHtml;
//return div.textContent;

String.prototype.stripHtml = function () {
   //  [^>]    ([^x]) A negated or complemented character set. That is, it matches anything that is not enclosed in the brackets.
   //    +      Matches the preceding expression 1 or more times. 
   //  /i     Perform case-insensitive matching.
   //   /g       Perform a global match, finds all matches.
   "use strict";/*ww w .j  a v  a2s. c  om*/

   var htmlRegex = /(<([^>]+)>)/ig;
   return this.replace(htmlRegex, '');
};

Related

  1. stripHTMLEntities()
    String.prototype.stripHTMLEntities = function() {
      var el = document.createElement("div");
      var html = this.replace(/<img/g, '<x-img');
      el.innerHTML = html;
      return el.innerText;
    
  2. stripHtml()
    String.prototype.stripHtml = function() {
       var tmp = document.createElement("DIV");
       tmp.innerHTML = this;
       return tmp.textContent || tmp.innerText || "";
    };
    
  3. stripHtml()
    String.prototype.stripHtml = function () {
        var _self = this.replace(/(<([^>]+)>)/ig, '');
        return _self;
    
  4. stripHtml()
    String.prototype.stripHtml = function() {
      return this.replace(/<[^>]+>/g, "");
    };
    console.assert("<p>Shoplifters of the World <em>Unite</em>!</p>".stripHtml() == "Shoplifters of the World Unite!");
    console.assert("1 &lt; 2".stripHtml() == "1 &lt; 2");
    
  5. stripHtml()
    String.prototype.stripHtml = function () {
      return this.replace(/<(?:.|\n)*?>/gm, '');
    };
    
  6. stripHtml()
    ?
    String.prototype.stripHtml = function () {
        return this.replace(new RegExp(/<[^>]+>/g), "");
    };
    
  7. stripTags()
    String.prototype.stripTags = function()
        return this.replace(/<\/?[^>]+>/gi, '');
    };
    
  8. stripTags()
    String.prototype.stripTags = function () {
      return this.replace(/(<([^>]+)>)/ig, "");
    };
    
  9. stripTags()
    String.prototype.stripTags = function(){
      var entity = {
        quot: '"',
        lt: '<',
        gt: '>',
        nbsp: ' '
      };
      return function ( ) {
        return this.replace(/&([^&;]+);/g,
    ...