Мне что-то вроде этого, что ты ищешь?
local original = " test"
local trimmed = original:match( "^%s*(.*)" )
local spaces = #original - #trimmed
print("The original word is [" .. original .. "] and the trimmed word is [" .. trimmed .. "] and there are " .. spaces .. " spaces.")
Выход:
The original word is [ test] and the trimmed word is [test] and there are 4 spaces.
(your_string):match '^ +':len ()