Lua, exception does not work on line end
Maybe exception is not the correct term, but I'm talking about using the following in lua's string.find () function:
[^exclude]
It doesn't seem to work if the character is not followed by anything, IE is the last character in the line.
Specifically, I am getting a list of running processes and trying to analyze them myself using LUA.
root@OpenWrt:/# ps | grep mpd
5427 root 21620 S mpd /etc/mpd2.conf
5437 root 25660 S mpd
It wouldn't be a problem if I could expect \ n every time, but sometimes ps doesn't list itself, which creates this problem. I want to combine:
5437 root 25660 S mpd
From this I will choose the PID for the kill command. I am running an OpenWRT build that doesn't support regex or exact parameters on killall, otherwise I would just do it.
(%d+ root%s+%d+ S%s+mpd[^ ])
The above pattern doesn't work unfortunately. This is because there is no character after the last character in the last line in my opinion. I've also tried:
(%d+ root%s+%d+ S%s+mpd$)
The above template returns nil.
(%d+ root%s+%d+ S%s+mpd[^ ]?)
The above template returns the first process (5427)
Maybe there is a better way to do this, or just a simple template change I can do to get it working, but I can't find one that will only capture the correct process. I cannot turn off PID or VSZ as they are variables. Maybe I'll have to see if I can compile OpenWRT with better killall support.
Anyway, thanks for taking the time to read this, and if it's a duplicate, I'm sorry, but I couldn't find anything similar to my predicament. Any suggestions are greatly appreciated!
source to share
Given:
local s = [[5427 root 21620 S mpd /etc/mpd2.conf
5437 root 25660 S mpd]]
Next pattern
string.match(s,"(%d+)%s+root%s+%d+%s+S%s+mpd[%s]-$")
returns: 5437 root 25660 S mpd
whereas this:
string.match(s,"(%d+%s+root%s+%d+%s+S%s+mpd[%s]%p?[%w%p]+)")
returns:
5427 root 21620 S mpd / etc / mpd2.conf
source to share