[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: splitting (was: A little suggestion about gfind)
- From: "Wim Couwenberg" <w.couwenberg@...>
- Date: Sun, 27 Apr 2003 14:56:10 +0200
Thomas Wrensch wrote:
> string.gsub(line, "([^%,]*)$",tadd)
> table.remove(t) -- get rid of extra field at end
Hmm. I didn't expect this to report an additional empty string as well...
The $ should consume the end-of-string I'd say, but it doesn't. That's
probably because the iteration in gsub (and gfind) is just offset based and
end-of-string is only a virtual character? But now 1) your solution is
still incorrect (try it on "aap,noot," and it drops the final empty part)
and 2) my suggested "(.-)[,$]" pattern wouldn't work either...
So, is this current $ matching in gsub/gfind a bug(let) or a feature?
Bye,
Wim
PS: Lua 5.0 offers string.gfind that is maybe better suited than
string.gsub in your example.