This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
OminousPenguin's profile picture

string.gmatch - Wiki lists as not working?

Started by OminousPenguin, 19 April 2012 - 01:52 PM
OminousPenguin #1
Posted 19 April 2012 - 03:52 PM
The Wiki page for the String API lists string.gmatch as not working and yet I can find no problem with it. Does anyone know of a problem with it?
OminousPenguin #2
Posted 19 April 2012 - 04:02 PM
Ok I found a bug:

Using any quantifier other than + will cause it to hang if that quantifier applies to the whole pattern and that pattern does not match the whole string.

Examples:

"abcdef":gmatch("%a*")   -- Works
"abc=def":gmatch("%a*")   -- Hang
"abc=def":gmatch("%a.*")  -- Works
"abc=def":gmatch("[%a.]*")  -- Hang
"abc=def":gmatch("[^=]*")  -- Hang
"abc=def":gmatch("([^=]*)=?") -- Works (Note: This produces the same result as the above pattern should)
"abcdef":gmatch("[^=]*")  -- Works
"abc=def":gmatch("[^=]*=")  -- Works

I am posting this list on the wiki. Please add to it as and when you discover other cases.