I want to match an equivalent of the regex pattern:
{(([^{}]+)|(?R))*}
which basically matches first { … } pair+content in a string. I cannot find a complete reference for what the lua pattern matching supports (everything either refers to compiled modules/extensions or alternate libs from string.match). I’m hoping someone here can help me, at least, with the Lua equivalent to R!
can you give some examples of what you’re trying to match ? that regex seems like more than one would need just to get content between two {}s.
here are some Lua examples:
local str, pat -- easy data str = "{Hello} in between {World} 1234 {123456}" pat = "{(%w+)}" for word in string.gmatch(str, pat) do print(word) end print("------") -- complex data str = "{'Hell0'} in between {W0rld} 1234 {1234} {'.4.4.4.'}" pat = "{([%w'.]+)}" for word in string.gmatch(str, pat) do print(word) end
-- output 2013-06-30 15:25:33.418 Corona Simulator[25712:f03] Hello 2013-06-30 15:25:33.418 Corona Simulator[25712:f03] World 2013-06-30 15:25:33.419 Corona Simulator[25712:f03] 123456 2013-06-30 15:25:33.419 Corona Simulator[25712:f03] ------ 2013-06-30 15:25:33.419 Corona Simulator[25712:f03] 'Hell0' 2013-06-30 15:25:33.419 Corona Simulator[25712:f03] W0rld 2013-06-30 15:25:33.419 Corona Simulator[25712:f03] 1234 2013-06-30 15:25:33.420 Corona Simulator[25712:f03] '.4.4.4.'
I was trying to guard against nested curlies to match first outermost pairing. This would allow for iteration through a string with irregular separators between json encoded strings.
I have solved the problem a different way, but this has highlighted the Lua matching seems primitive. Corona has to live in a modern-day ecosystem where protocols and formats are rather complex and more powerful pattern matching is needed.
can you give some examples of what you’re trying to match ? that regex seems like more than one would need just to get content between two {}s.
here are some Lua examples:
local str, pat -- easy data str = "{Hello} in between {World} 1234 {123456}" pat = "{(%w+)}" for word in string.gmatch(str, pat) do print(word) end print("------") -- complex data str = "{'Hell0'} in between {W0rld} 1234 {1234} {'.4.4.4.'}" pat = "{([%w'.]+)}" for word in string.gmatch(str, pat) do print(word) end
-- output 2013-06-30 15:25:33.418 Corona Simulator[25712:f03] Hello 2013-06-30 15:25:33.418 Corona Simulator[25712:f03] World 2013-06-30 15:25:33.419 Corona Simulator[25712:f03] 123456 2013-06-30 15:25:33.419 Corona Simulator[25712:f03] ------ 2013-06-30 15:25:33.419 Corona Simulator[25712:f03] 'Hell0' 2013-06-30 15:25:33.419 Corona Simulator[25712:f03] W0rld 2013-06-30 15:25:33.419 Corona Simulator[25712:f03] 1234 2013-06-30 15:25:33.420 Corona Simulator[25712:f03] '.4.4.4.'
I was trying to guard against nested curlies to match first outermost pairing. This would allow for iteration through a string with irregular separators between json encoded strings.
I have solved the problem a different way, but this has highlighted the Lua matching seems primitive. Corona has to live in a modern-day ecosystem where protocols and formats are rather complex and more powerful pattern matching is needed.