Search code examples
stringlua

lua split into words


I have a string in lua.

It's a bunch of [a-zA-Z0-9]+ separated by a number (1 or more) spaces.

How do I take the string and split it into a table of strings?


Solution

  • s = "foo bar 123"
    words = {}
    for word in s:gmatch("%w+") do table.insert(words, word) end