0

I am trying to align code using align-regex but I could not figure out how to solve the below problem.

This is what I have:

public class Person
{
    public static String id = "";
    private String name = "";
    public int age = 10;

} 

This is what I am trying to get:

public class Person
{
    public  static String id =       "";
    private String name   =  "name";
    public  int    age    =  10;

} 

Actually I just want to separate them into each column.

I have tried M-x align-regex RET \(s-*\)\s- and many more but none is working. Please help me solve this or advice me.

tammary
  • 3
  • 3

1 Answers1

0

If you don't mind re-indenting afterwards:

C-uM-x align-regex RET \(\s-+\) RETRETRETy

To re-activate the mark and re-indent should then be:

C-xC-xTAB


To avoid the need to re-indent, we need to enable it to ignore as much of the initial space as possible:

C-uM-x align-regex RET \s-*\(\s-+\) RETRETRETy

phils
  • 50,977
  • 3
  • 79
  • 122
  • it's work really nice but it adds one more TAB to the code everytime I try the command. Is that I done something wrong? – tammary Oct 14 '18 at 07:52
  • Does https://stackoverflow.com/a/8129994/324105 help? – phils Oct 14 '18 at 08:28
  • And if you are indenting with only tabs and aligning with only spaces, then that gives you an easy way to ignore the indentation, by aligning on \( +\) (i.e. one-or-more spaces). – phils Oct 14 '18 at 08:34