Here motivated by the accepted answer, it might be useful to extend the function to remove both leading and trailing spaces.
Find What: ^\h+|\h+$|(\h+)
Replace With: (?{1}\t:)
^\h+
→ Leading spaces (uncaptured).
(\h+)
→ Captures internal spaces (Group 1).
\h+$
→ Trailing spaces (uncaptured).
If Group 1 (internal spaces) exists → Replace with \t
(tab).
Else (leading/trailing spaces) → Replace with nothing (empty string).