Creating a regex example Align by method name - cpmcgrath/codealignment GitHub Wiki
This wiki is to show how you can create your own regexes. The end result should be able to align the following code...
bool IsBlah();
long int GetSomeValue(int someParameter) const;
as
bool IsBlah();
long int GetSomeValue(int someParameter) const;
Code alignment know nothing about the language you're using - and it shouldn't, it would add an unnecessary level of complexity. So the first thing we must think about is how do we identify the method name? The method name should always end with an open bracket. It may also have spaces before the bracket.
So we want to align by the first character of a string which is followed by a bracket.
Most complex regexes will be based off the "Align by space" regex.
\s+(?<x>[^\s])
That's pretty much what we want except it doesn't have the bracket check...
\s+(?<x>[^\s]) //Find a non-space character after one or more spaces
\s+(?<x>[^\s\(]) //Find a non-space, non-bracket character after one or more spaces
\s+(?<x>[^\s\(]+) //Find a series of non-space, non-bracket characters after one or more spaces
\s+(?<x>[^\s\(]+)\( //Find a series of non-space, non-bracket characters after one or more spaces which is followed by a bracket
\s+(?<x>[^\s\(]+)\s*\( //Find a series of non-space, non-bracket characters after one or more spaces
which is followed by zero or more spaces then a bracket.
The result...
\s+(?<x>[^\s\(]+)\s*\(
You can then set this as a shortcut in the Shortcuts option screen