lua-users home
lua-l archive

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

On 16/11/13 20:59, Michael Savage wrote:

Hi lua-l,

( "[a] [b] c" ):match( "%[(.-)%] c" )
-> "a] [b"

From or

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;

The shortest possible sequence for the above is "b". Is this a bug?


It is not, as it returns the first match [1]. If you wanted to capture the last sequence in square brackets you could prefix it with a greedy match:
( "[a] [b] c" ):match( ".*%[(.-)%] c" )