Search code examples
stringsearchluaptokax

Why is `sData` a non-nil value?


Execution of the code is here on eval.in

sMessage = "<hjpotter92> +help|"
local _, _, sCmd, sData = sMessage:find( "%b<>%s[%+%-%*%/%!%#%?](%w+)%s?(.*)|" )
print( _, sData, sCmd  )

The output of print says the my sData is a value with empty string.

Why is this value not nil? I created an entire project based on sData being nil for such a case, and I find that it is not so.


I've resolved the trouble by using this block

if sData:len() == 0 then 
    sData = nil 
end

So, I'm not seeking a solution to make this work. I'm just asking, why is it not a nil value?


Solution

  • Why it should be nil?
    You are getting successful match of pattern .* with empty string.
    nil means "no match found".
    example