lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Try pattern = "(%S+)".  This will match groups of non-spaces.  Note that the
parens are to capture the match.

- Peter Shook

> local word_table = { n = 0 }
> gsub(text, pattern, function (word)
>                           tinsert(%word_table, word)
>                         end)
>
> for separating tokens, but I couldn't find out a way to split strings like
> "Hello, world!" into ["Hello", ",", "world", "!"] -- for what I'd use a
> pattern like "\w+|[^\w\s]+".
> Any suggestions about how to implement it?