Write lua script that extracts the word between ":" and " Text" in each line in the…
- User
Write lua script that extracts the word between ":" and " Text" in each line in the string "1:First Text\n2:Second Text\n3:Third Text" and prints the extracted words as a new string where they are separated by ", "
- Assistant
Here is an Lua script that extracts the word between ":" and " Text" in each line in the string "1:First Text\n2:Second Text\n3:Third Text" and prints the extracted words as a new string where they are separated by ", ":
-- Extract the word between ":" and " Text" in each line local function extractWords(str) local words = {} local pattern = ":".. "\n" for line in str:gmatch(pattern) do table.insert(words, string.match(line, pattern)) end return table.join(words, ", ") end -- Example usage local str = "1:First Text\n2:Second Text\n3:Third Text" print(extractWords(str)) -- Output: "First, Second, Third"
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.