I am trying to write a simple command line script to fix some spaces and require replacing the occurrence of two spaces with a tab, but only if it appears at the beginning of the line (prefix only with other tabs.)
I came up with s/^(\t*) /\1\t/g; , which works fine if I run a few passes, but I don't know enough about perl to know how to loop until the string changes, or if there is a regular expression to handle it.
My only thought was to use lookbehind, but it cannot be of variable length. I would be open to a solution without regular expressions if it was short enough to fit into a fast command line script.
For reference, the current perl script is executed as follows:
perl -pe 's/^(\t*) /$1\t/g'
gnarf source share