I want to turn a string like "hello-world" into a list of strings: {"hello-", "world"}
I can easily split by hyphens:
local r = {}
for word in text:gmatch("[^-]+") do
table.insert(r, word)
end
and I can approximately put it together by assuming each word was followed by a hyphen:
for i, word in pairs(r) do
if i < #r then
word[i] = word[i] .. "-"
end
end
but that is assuming that there is precisely one hyphen after each word and that the string doesn't start or end with hyphens.
I was considering something like this:
local r = {}
for word in text:gmatch("%-|[^-]+") do
table.insert(r, word)
end
but Lua string patterns doesn't have support for "either" (what I wanted by the |), so that pattern doesn't work.
Is there any way to do this without going character-by-character?
More examples:
"--a--b---c" --> {"--a--", "b---", "c"} or {"--", "a--", "b---", "c"} -- I don't care which
"hello-there-person" --> {"hello-", "there-", "person"}
"hello" --> {"hello"}

2 comments
Any idea what the rule is that let's you use
-*instead of%-*? Is it because it's preceded by a*?Not entirely sure. It may be that * takes precedence over -, and so -* is grouped together as one set before - is registered as a modifier, because -*, -+, and -? still work.