lua-users home
lua-l archive

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

On 7/26/07, Eike Decker <> wrote:
> Hi
> I am trying to find a regular expression that matches each line of an input
> string but cannot find an expression that needs no additional checks. What I
> have tried so far:
> for line in str:gmatch("[^\n]+") do
> matches not empty lines
> for line in str:gmatch("([^\n]*)\n?") do
> matches every line correctly BUT returns an empty string after the last
> character, i.e.
> "123" results in
> line = "123"
> line = ""
> I cannot get rid of the last match, so I wonder if there is an elegant
> expression to match every line correctly, even empty lines and without adding
> "virtual" lines.
How about this this...  it will give you every line...


No need to make it try to match the newline char...  Not sure how it
handles the end-of-string case however...
Thomas Harning Jr.