[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: EndOfLine Pattern Matching
- From: Tom Wrensch <twrensch@...>
- Date: Wed, 3 Apr 2002 14:18:08 -0800 (PST)
I don't think you can do this directly with strfind. The pattern matcher
built into Lua cannot handle disjunctions of multicharacter 'tokens'.
(Note that I assume you mean a linefeed character when you use "\n" I
think this works okay in Lua).
What you could do is use strfind to look for a character that *could* be
one of these patterns using a character class. Something like this:
local s,e = strfind(mystring, "[\r\n]")
Then look at the string to see if the next character is an allowed
follow on character.
Another approach would be to allow any sequence of \n and \r characters
to count as an end of line. This is more general than your definition,
but can be expressed without the disjunction using a character class as
local s,e = strfind(mystring, "[\r\n]+")
This might be closer to what you want.
On Wed, 3 Apr 2002, Markus Huber wrote:
> How can I match all possible EndOfLines in strfind() with a Lua pattern?
> EndOfLine is \n\r
> or \r\n
> or \n
> or \r
> but \n\n are two EndOfLines with an empty string between
> also \r\r
> Since one hour I try to define a pattern that matches all possible
> EndOfLine definitions.