[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Regular expression for matching lines
- From: Eike Decker <eike@...>
- Date: Mon, 30 Jul 2007 00:31:19 +0200
Zitat von "Thomas Harning Jr." <email@example.com>:
> On 7/26/07, Eike Decker <firstname.lastname@example.org> wrote:
> > Hi
> > I am trying to find a regular expression that matches each line of an
> > string but cannot find an expression that needs no additional checks. What
> > 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
> > "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.
Won't work (tried it out) for the string
it will produce
Every linebreak is captured as a zerolength string.