Javascript String stripTags()

Description

Javascript String stripTags()


var str = "<p><strong><em>PHP Exercises</em></strong></p>";


String.prototype.stripTags = function() {
  return this.replace(/<\/?[^>]+>/g, '');
};

console.log(str.stripTags());/*from  w ww.ja  va 2s .  c o m*/

Javascript String stripTags()

//from prototype library

String.prototype.stripTags = function()
{
    return this.replace(/<\/?[^>]+>/gi, '');
};

Javascript String stripTags()

String.prototype.stripTags = function () {
  return this.replace(/(<([^>]+)>)/ig, "");
};

/**/* www.j  a  v  a2  s  .  c o m*/
 * sprintf-like functionality
 * replaces {0}, {1}... in a string with arguments passed to a function
 */
if (!String.prototype.format) {
  String.prototype.format = function() {
    var args = arguments;
    return this.replace(/{(\d+)}/g, function(match, number) {
      return typeof args[number] != 'undefined'
        ? args[number]
        : match
        ;
    });
  };
}

Javascript String stripTags()

String.prototype.stripTags = function () {
    return this.replace(/\<.*\>/gi, '');
}

Javascript String striptags()

String.prototype.striptags = function() {
 return this.replace(/(<.*?>)/g).replace(/undefined/g,'?');
}

Javascript String stripTags()

String.prototype.stripTags = function(){
 var entity = {/*from  ww  w  . j  a v a2  s  . c o m*/
  quot: '"',
  lt: '<',
  gt: '>',
  nbsp: ' '
 };
 return function ( ) {
  return this.replace(/&([^&;]+);/g,
   function (a, b) {
    var r = entity[b];
    return typeof r === 'string' ? r : a;
   }
  );
 };
}( );



PreviousNext

Related