I have following code to replace left spaces with a specific string but, It is not working as I want.
You may use a lambda function as 2nd argument of .replace:
.replace
const s = ' asdadasdad as asdasd asasd'; var repl = s.replace(/^\s+/, m => m.replace(/\s/g, 'x')); console.log(repl);