Javascript Regular Expressions Trim white space from beginning and end

Description

Javascript Regular Expressions Trim white space from beginning and end


let testString = "   this is the string    ";
console.log("before:" + testString);

// trim white space from the beginning
testString = testString.replace(/^\s+/,"");

// trim white space from the end
testString = testString.replace(/\s+$/,"");

console.log("after:" + testString);



PreviousNext

Related