lua-users home
lua-l archive

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


> ------------------------------
> Date: Tue, 14 Dec 2010 19:31:08 +0200
> From: Dirk Laurie <dpl@sun.ac.za>
> Subject: Baffling behaviour of string.match
> To: Lua mailing list <lua-l@lists.lua.org>
> Message-ID: <20101214173108.GA5201@rondloper>
> Content-Type: text/plain; charset=us-ascii
> 
> I don't understand this.
> 
> --[[
> > s='abbcd'; return a:match('b')
> b
> > s='abbcd'; return a:match('bb')
> bb
> > s='abbcd'; return a:match('b*')
> 
> >
> --]]
> 
> I expected the last match to be also "bb".
> 
> Dirk

In a pattern, "*" means "match 0 or more repetitions". string.match
found zero repetitions of 'b' at the start of the string (in the "null
space" prior to the letter a).

John Giors
Independent Programmer
Three Eyes Software
jgiors@ThreeEyesSoftware.com
http://ThreeEyesSoftware.com