This is a follow up to a question I asked in the
CodePudding user response:
You can use a function as a replacement argument:
result = string.gsub ( s, '\\sitem%s (.-)(\n\\)' , '\\item\\makefirstuc {%1},%2')
See the online demo.
Details:
\\sitem
- a\sitem
fixed string%s
- one or more whitespaces(.-)
- Group 1 (%1
): any zero or more chars as few as possible(\n\\)
- Group 2 (%2
): a newline and a\
.
CodePudding user response:
The .
pattern matcher in Lua's patterns matches new lines, so something like this would work:
s = s:gsub(
"\\item%s (. )",
function(it)
return "\\item\\makefirstuc " .. it:gsub("\n", " ")
end
)