Regex : How to remove spaces from the left of a string with Regex

Use :

replace(/\s+$/,"");

Example :

var test = "      xxxxx - yyyyyyy";
var firstResult = test.split("-")[0].trim(); // "      xxxxx"
var final = firstResult.replace(/\s+$/,""); // "xxxxx"

Leave a comment