Skip to content
Chris McGrath edited this page May 2, 2016 · 5 revisions

This wiki is to show how you can create your own regexes. The end result should be able to align the following code...

[ "Item 1", "Item 2", "Item 3", "Item 4" ]
[ "Item One A", "Item Two B", "Item Three C", "Item Four D" ]

as

[ "Item 1",     "Item 2",     "Item 3",       "Item 4" ]
[ "Item One A", "Item Two B", "Item Three C", "Item Four D" ]

We could use "Align by String" but there's a lot of spaces we don't want to align by, which means we can't use alignment chaining. Also we would have to manually add spaces to get it to align the correct spaces.

What we want is to align by the first non-space character after a comma

Most complex regexes will be based off the "Align by space" regex.

\s+(?<x>[^\s])

We can manipulate it as below...

\s+(?<x>[^\s])  //Find a non-space character after one or more spaces
,\s+(?<x>[^\s]) //Find a non-space character after a comma and one or more spaces
,\s*(?<x>[^\s]) //Find a non-space character after a comma and zero or more spaces

The result...

,\s*(?<x>[^\s])

You can then set this as a shortcut in the Shortcuts option screen with all options ticked.

Clone this wiki locally