To work with lua captures from the command line, I wrote a script:

#!/usr/bin/lua msg = arg[1] or error('No matching pattern!', 2) text = io.read('*a') for str in string.gmatch(text, msg) do io.write(str, '\n') end 

The only problem is: how to make for forwards all capture results in a row / table? That is, the pattern ()(%S+)() will only return the position of the beginning of the word - 1.

    1 answer 1

     #!/usr/bin/lua local msg = arg[1] or error('No matching pattern!', 2) local text = io.read('*a') local iterator = text:gmatch(msg) repeat local array = {iterator()} if array[1] then print(table.concat(array, ', ')) end until not array[1]