[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Implementing 'or' in gsub() pattern
- From: "Peter Shook" <pshook@...>
- Date: Mon, 31 Mar 2003 16:14:08 -0500
Here is a more compete answer.
$ cat try.lua
a = "hello, there!"
function words(s)
local wl = {}
s = gsub(s, "(%p+)", " %1 ") -- space out punctuation
gsub(s, "(%S+)", function(w) tinsert(%wl, w) end)
return wl
end
w = words(a)
foreachi(w,print)
$ lua try.lua
1 hello
2 ,
3 there
4 !
- Peter Shook
> "Hello, world!" into ["Hello", ",", "world", "!"] -- for what I'd use a
> pattern like "\w+|[^\w\s]+".
> Any suggestions about how to implement it?