Node.js examples for String:Char
Remove all BUT the characters of a given string from a string
/* Remove all BUT the characters of a given string from a string * * "Abracadabra".remove('ar') => "raaara" *///w w w .ja va 2 s .c om String.prototype.filterchars = function ( chars ) { if ( arguments.length > 1 ) { chars = Array.prototype.join.call( arguments, '' ); } var rx = RegExp.compile('[^'+RegExp.escape(chars)+']', 'g'); return this.replace( rx, '' ); };