I'd like to be able to fix a Text File's tabs/spaces indentation.
Currently each line has spaces in random locations for some reason.
For example:
space
tab
if
-> tab
if
space
tab
space
tab
if
-> tab
tab
if
tab
tab
space
if
-> tab
tab
if
etc.
It should not affect anything after the first word, so only the indentation will be affected: So tab space if space boolean
should be changed to tab if space boolean
not tab if tab boolean
.
The regex command should keep the correct number of tabs and just remove the spaces. If there are 4 spaces in a row it should be converted to a tab instead.
Thank you for your help. If you could also explain how your regex works it would be very much appreciated as I'm trying to learn how to do my own regex instead of always asking others to do it.
If you need any more information or details please ask I'll respond as quickly as I can.
I can accomplish this for a single case at a time like so:
For spaces first: Find: space*if
Replace: if
This only works for lines with no tabs and where the first word is if so I would do this for the starting word of the line.
Then I would repeat with space*\tif
.
Looks like I can match a word without capturing by doing (?:[A-Za-z])
So I can just swap out the if
for this and it'll work better.