I'm writing a script to automate the mantainment of my makefile. I need a Lua pattern that matches the following lines:
# objects {
objects = build/somefile1.o \
build/somefile2.o \
...
build/somefileN.o \
# } objects
I tried with %# objects %{[a-z%.%s%/%\\]+%# %} objects
but it doesn't seem to work.
I suggest using:
To make it work for cases when the match is at the start of the string, you need to prepend the string input with a newline. Here, a newline is matched first, then
# objects
, then a space, then%b{}
matches balanced nested curly braces (if any) and thenobjects
is matched.When running the extraction, the captured part (within
(...)
) will be returned withstring.gmatch
.See the Lua online demo