Regex to change the number of spaces in an indent level

后端 未结 4 2108
天命终不由人
天命终不由人 2021-02-12 23:54

Let\'s say you have some lines that look like this

1  int some_function() {
2    int x = 3;  // Some silly comment

And so on. The indentation i

4条回答
  •  既然无缘
    2021-02-13 00:29

    In some regex flavors, you can use a lookbehind:

    s/(?<=^ *)  /   /g
    

    In all other flavors, you can reverse the string, use a lookahead (which all flavors support) and reverse again:

     s/  (?= *$)/   /g
    

提交回复
热议问题