Replace all left spaces with a specific string

前端 未结 5 518
时光说笑
时光说笑 2020-12-19 11:18

I have following code to replace left spaces with a specific string but, It is not working as I want.

5条回答
  •  庸人自扰
    2020-12-19 11:49

    You may use a lambda function as 2nd argument of .replace:

    const s = '  asdadasdad as asdasd asasd';
    
    var repl = s.replace(/^\s+/, m => m.replace(/\s/g, 'x'));
    
    console.log(repl);

提交回复
热议问题