Javascript String strip()
String.prototype.strip = function() { return this.replace(/^\s+/, '').replace(/\s+$/, ''); };
String.prototype.strip = function() { return this.replace(/^\s+|\s+$/g,""); };
var DECODE_HTML_CHARACTERS = { 'nbsp': ' ', 'amp': '&', 'quot': '"', 'lt': '<', 'gt': '>' }; String.prototype.strip = function() { var self = this.replace(/<\/?[^>]+(>|$)/g, ''); return self.replace(/&(nbsp|amp|quot|lt|gt);/g, function(match, k) { return DECODE_HTML_CHARACTERS[k] || k; });// w w w . jav a 2 s.c o m };
//assignment: check string to see if it is a palindrome String.prototype.strip = function() { return this.replace(/\W?\s+/g,""); }; function palindrome(str) { var stripped = str.toLowerCase().strip(); var reversed = stripped.split("").reverse().join(""); if (stripped === reversed) { return true; } else {// ww w .ja v a 2 s. c o m return false; } } palindrome("eye"); palindrome("lasagna is an asian gas al");
String.prototype.strip = function() { return this.replace(/^\s+/, '').replace(/\s+$/, ''); }
String.prototype.strip = function() { return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '').replace(/:$/, "").replace(/\.$/, ""); }
String.prototype.strip = function(){ return this.replace(/(^\s+|\s$)/gi, ''); };
String.prototype.strip = function () { var s = this.valueOf(); s = s.replace(/([\s]+$)/, ''); s = s.replace(/(^[\s]+)/, ''); return s;/*from w ww . j ava2s .c o m*/ };