You are not logged in.
Pages: 1
Maybe I'm just too stupid to get it. Im trying to parse a string (for an battery widget in awesome):
The string I want to parse is something like that:
Battery 1: discharging, 46, 02:03:04 remaining
I'm just interested in the last part (02:03:04 remaining), so I tried the following:
for s in string.gmatch(output, "(%w+) remaining))
But I only get the last two digits (04). I think that gmatch treats the : as a seperator and therefore 04 already fulfills the regular expression. What can I do now?
Last edited by freigeist (2008-11-18 09:21:37)
Elfenbeinturm.cc
a metaphysical space of solitude and sanctity: http://www.elfenbeinturm.cc
Offline
Solved it...but I'm not satisfied, there must be an more elegant way to do this
for s in string.gmatch(output, "(%d:%d+)%:") do
s2 = s2..s..':'
end
s2=string.sub(s2,1,string.len(s2)-1)
return {s2..' h'}
Last edited by freigeist (2008-11-18 09:38:03)
Elfenbeinturm.cc
a metaphysical space of solitude and sanctity: http://www.elfenbeinturm.cc
Offline
Do you get the string by executing a shell command? If so, why not use sth. like cut to extract the relevant bits on the fly?
I.e. I use the following:
local f = io.popen("acpi -b | cut -d, -f2-3")
Offline
I'm just interested in the last part (02:03:04 remaining), so I tried the following:
for s in string.gmatch(output, "(%w+) remaining))
But I only get the last two digits (04). I think that gmatch treats the : as a seperator and therefore 04 already fulfills the regular expression. What can I do now?
Try this:
for s in output:gmatch('([%w:]+) remaining')
Offline
Pages: 1