newString = string.replace(/s+/g,' ').trim();
const removeSpaces = str => str.replace(/s/g, '');
// Example
removeSpaces('hel lo wor ld'); // 'helloworld'
var str = " Some text ";
str.trim();
// str = "Some text"
var str = " Hello World! ";
alert(str.trim());
var str = '/var/www/site/Brand new document.docx';
document.write( str.replace(/s/g, '') );
let text = "I love you"
text = text.replace( / +/g, '_') // replace with underscore ('_')
console.log(text) // I_love_you
var puzzle1=myTrim($("#puzzleinput").val());
function myTrim(x) {
return x.replace(/^s+|s+$/gm,'');
}
var str = '/var/www/site/Brand new document.docx';
document.write( str.replace(/s/g, '') );
Run code snippetHide results