Javascript String stripHtml()
? // Extension method stripHtml for string object String.prototype.stripHtml = function () { return this.replace(new RegExp(/<[^>]+>/g), ""); };
String.prototype.stripHTML = function(){ return this.replace(/<(?:.|\s)*?>/g, ""); };
String.prototype.stripHtml = function () { var regex = /(<([^>]+)>)/ig return this.replace(regex, ""); }
String.prototype.stripHtml = function () { var self = this; var text = self.replace(/&(lt|gt);/g, function (strMatch, p1) { return (p1 == "lt") ? "<" : ">"; });//from ww w.j a v a2 s . c o m return text.replace(/<\/?[^>]+(>|$)/g, ""); }
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp 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 < 2".stripHtml() == "1 < 2");
String.prototype.stripHtml = function() { var tmp = document.createElement("DIV"); tmp.innerHTML = this;//w ww.j av a 2 s . c o m return tmp.textContent || tmp.innerText || ""; };
String.prototype.stripHtml = function () { //got regex from http://www.dotnetperls.com/remove-html-tags var pattern = /<.*?>/g; return this.replace(pattern, ""); }
// Requirement 6//from www . j a v a 2 s . c o m String.prototype.stripHtml = function () { // Sandbox http://www.regexpal.com/?fam=96086 // Modifiers used g=global m=multiline return this.replace(/<(?:.|\n)*?>/gm, ''); };
//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";/*from w ww . java 2 s .c om*/ var htmlRegex = /(<([^>]+)>)/ig; return this.replace(htmlRegex, ''); };
/**/* w w w.j av a2 s . c o m*/ @Name: String.prototype.stripHTML @Author: Paul Visco @Version: 1.0 11/19/07 @Description: Removes all HTML tags from a string @Return: String The original string without any HTML markup @Example: var myString = 'hello <p>world</p> on earth'; var newString = myString.stripHTML(); //newString = 'hello world on earth' */ String.prototype.stripHTML = function(){ var re = new RegExp("(<([^>]+)>)", "ig"); var str = this.replace(re, ""); var amps = [" ", "&", """]; var replaceAmps =[" ", "&", '"']; for(var x=0;x<amps.length;x++){ str = str.replace(amps[x], replaceAmps[x]); } re = new RegExp("(&(.*?);)", "ig"); str = str.replace(re, ""); return str; };