1

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?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • I would fill in the small components first, before working on the broader project scope. That being said, to my knowledge, `find` never returns `nil`. –  Apr 09 '13 at 03:42
  • @Telthien You might want to [reconsider that statement](http://eval.in/15744). – hjpotter92 Apr 09 '13 at 03:48
  • I retracted my answer, since now that I understand what you're asking, I don't know what causes it. –  Apr 09 '13 at 04:27

1 Answers1

1

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

Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64
  • Then there is no other way to use find/match so that `sData` will be a `nil`? It doesn't actually affect much though, since I have used the if-statement instead. – hjpotter92 Apr 09 '13 at 11:27
  • @hjpotter92 - Empty string and `nil` are conceptually different objects, why you want to mix them up? – Egor Skriptunoff Apr 09 '13 at 11:36