I'm trying to learn how patterns (implemented in string.gmatch, etc.) do work in Lua 5.3, from the reference manual.
(Thanks @greatwolf for correcting my interpretation about the pattern item using *.)
What I'm trying to do is to match '(%(.*%))*' (substrings enclosed by ( and ); for example, '(grouped (etc))'), so that it logs
(grouped (etc))
(etc)
or
grouped (etc)
etc
But it does nothing ???? (online compiler).
local test = '(grouped (etc))'
for sub in test:gmatch '(%(.*%))*' do
print(sub)
end
*.instead of.*? - Egor Skriptunoff.\*ends up using the next character class (in the question example,%, at%)), same as.*%, I guess. - Klaider*,-,+etc. comes after the char class you want to match. For example to match letters use%a*,.*will greedy match any character. Your example just uses*kleene star but nothing precedes it so it's not well-formed. - greatwolf%a+%s(%(.-%)), which means match 1 or more letters(case insensitive) followed by optional space followed by any characters in(). On match capture the stuff in the parenthesis. - greatwolf