lua-users home
lua-l archive

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


Then should i say that it is same as "*?", which is common in other popular languages ?


On Thu, May 3, 2012 at 8:12 PM, liam mail <liam.list@googlemail.com> wrote:
On 3 May 2012 20:02, Emeka <emekamicro@gmail.com> wrote:
> Hello All
>
>
> I stumbled on the above while going through Lua manual... I need your help
> to here.
>
>      x = string.gsub("4+5 = $return 4+5$", "%$(.-)%$", function (s)
>            return loadstring(s)()
>          end)
>
> I am of the view that it should be,
>
>      x = string.gsub("4+5 = $return 4+5$", "%$(.+)%$", function (s)
>            return loadstring(s)()
>          end)
>
>
> My question is what is "-" in the above pattern?
>
> Regards, \Emeka
> Satajanus  Nig. Ltd
>
>
>

'-' is a none greedy, zero or more repetitions [1][2], where as "+" is
a greedy one or more repetitions pattern

[1] "a single character class followed by '+', which matches 1 or more
repetitions of characters in the class. These repetition items will
always match the longest possible sequence;
a single character class followed by '-', which also matches 0 or more
repetitions of characters in the class. Unlike '*', these repetition
items will always match the shortest possible sequence;"
[2] http://www.lua.org/manual/5.1/manual.html#5.4.1




--
Satajanus  Nig. Ltd