lua-users home
lua-l archive

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


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.

Thanks

Eike