title: Split string with specified delimiter in lua
body: <p>I'm trying to create a split() function in lua with delimiter by choice, when the default is space.
  the default is working fine. The problem starts when I give a delimiter to the function. For some reason it doesn't return the last sub string.
  The function:</p>
  
  <pre><code>function split(str,sep)
  if sep == nil then
      words = {}
      for word in str:gmatch("%w+") do table.insert(words, word) end
      return words
  end
  return {str:match((str:gsub("[^"..sep.."]*"..sep, "([^"..sep.."]*)"..sep)))} -- BUG!! doesnt return last value
  end
  </code></pre>
  
  <p>I try to run this:</p>
  
  <pre><code>local str = "a,b,c,d,e,f,g"
  local sep = ","
  t = split(str,sep)
  for i,j in ipairs(t) do
      print(i,j)
  end
  </code></pre>
  
  <p>and I get:</p>
  
  <pre><code>1   a
  2   b
  3   c
  4   d
  5   e
  6   f
  </code></pre>
  
  <p>Can't figure out where the bug is...</p>