[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Regular expression for matching lines
- From: "Thomas Harning Jr." <harningt@...>
- Date: Sat, 28 Jul 2007 19:09:20 -0400
On 7/26/07, Eike Decker <eike@cube3d.de> 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...
str:gmatch("([^\n]*)")
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.