I am trying to split a string to substrings using Lua. Using the pattern in the for loop below I would have expected 4 matches but I only get 2.
print(words[1])
displays
"###Lorem ipsum dolor sit amet, Gruß consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam \n"
and print(words[2])
displays
"###At vero eos et accusam et justo duo dolores et ea rebum. Stet clita \nkasd gubergren, no sea takimata Gruß sanctus est \n"
Can someone please explain me this behavior ?
i=0
content = "###Lorem ipsum dolor sit amet, Gruß consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam \n ###voluptua. ###At vero eos et accusam et justo duo dolores et ea rebum. Stet clita \nkasd gubergren, no sea takimata Gruß sanctus est \n###XLorem ipsum dolor sit amet. Lorem ipsum \ndolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor \ninvidunt ut labore et Gruß dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.sdl"
for word in string.gmatch(content, '###')
do i = i+1 end
if(i>1) then
content = content .. '###'
else end
words= {}
for y in string.gmatch(content,"(###.-)###")
do
table.insert(words, y)
end
print(words[3])
Your first loop does find four matches. Try this to confirm:
If that works for you, then save
word
in the loop as needed.