|
'-' is a none greedy, zero or more repetitions [1][2], where as "+" isOn 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
>
>
>
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