[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: split method?
- From: Wesley Smith <wesley.hoke@...>
- Date: Mon, 27 Jun 2011 11:54:54 -0700
>> I think this function could be a lot simpler. string.gmatch is more suited to this type of problem than string.find IMHO:
>> ... gmatch(string.format("([^%s]+)%s?", delim, delim)) ...
> I try to avoid regex's. Just because a block of code is shorter doesn't mean it’s simpler. I find them largely opaque to easy comprehension.
To each his own. For "-" it ends up being "([^-]+)-?". I too used to
be afraid of string patterns, but once you get over that, they're
quite pleasant to work with. FWIW, Lua's patterns are a much reduced
set of ops compared to full blown regexs, making it much easier to
understand them. Also, for the record I didn't say it was simpler
because it was shorter. I said it's simpler because string.gmatch
maps to your problem better. The shortness comes as a consequence.