[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Regex question
- From: Rici Lake <lua@...>
- Date: Thu, 18 Aug 2005 18:33:53 -0500
On 18-Aug-05, at 6:26 PM, Aaron Brown wrote:
Keith Pimmel wrote:
I try anchoring it with the following
_,_,last = string.find(str,'(^\n]*$)')
_, _, last = string.find(str, '([^\n]*)$')
Lua (for some reason) doesn't like anchors to be inside
That will suffer from two problems:
First, if the string ends with \n, it will return an empty string,
probably not what was desired.
Second, it will be much slower than you might like; the pattern will be
attempted at every character position in the string.
If you knew that the string did not end with a \n, and that there was
always at least two lines (or that the string did start with a \n),
this would be quite a bit faster:
but I suspect that Shannon's for loop using string.gfind is actually
the best solution.