I would like to use search and replace with regular expressions. The shortest way I could think of is to search and replace in two passes.:
First replace:
[[:blank:]]+
<blank repeated the number of times as long as the first string>
Regular expression box checked
Second replace:
^(.{9})[[:s:]]+([^[:s:]]+)[[:s:]]+([^[:s:]]+)$
\1 \2 \3
Regular expression box checked
Problems I need help solving:
For the first replace, instead of hitting the spacebar x times I would like to be able to specify the repeat number in code something like: <space>{9}
For the first and second replace I would like to prompt the user for the length of the string instead of hard-coding the number (in this case 9).
It would be great if the above two steps could be combined into one.
I have searched and found the following links which point to a Perl solution which is more complicated than I'd like.
I don't think there's a practical way to align text using regular expressions (though I'm happy to be proven wrong), but would you consider using tabs to solve your problem? That is what they're for, after all.
Step 1: Align the "AS" keywords with tabs Find what: _+AS_+[replace the underscores with spaces] Replace with: \tAS_[replace the underscore with a space]
Step 2: Set the tab width
1. Click View > Document Properties.
2. Click Tabulation.
3. In Default tab spacing, enter the width of the longest "x" string plus 1 (in your example, 10).
4. Select Convert existing tabs to spaces when saving files.
Step 3: Convert the tabs to spaces
5. Save the file.
That is not the solution I was hoping for but it does work. You are correct that that is what tabs were meant for. I was hoping to be able to highlight a range, select a menu option pointing to a macro, and be prompted for a column number. Alas, that is not meant to be.