以下のパターンは、次の場合に機能するはずです。
- IP アドレスは 10 進数のドット表記です。
- MAC アドレスは、コロンで区切られた 16 進数です。
注: 質問で提供された MAC アドレスには、16 進数ではない「G」が含まれています。
編集:あなたの質問について詳しく考えた後、複数のインスタンスをテーブルに取り込む方法を示すために回答を拡張しました。
sString = [[
IP: 192.168.128.16
MAC: AF:3F:9F:c9:32:2E
Expires: Fri Aug 1 20:04:53 2010
Time Left: 11040 seconds
IP: 192.168.128.124
MAC: 1F:3F:9F:c9:32:2E
Expires: Fri Aug 3 02:04:53 2010
Time Left: 1140 seconds
IP: 192.168.128.12
MAC: 6F:3F:9F:c9:32:2E
Expires: Fri Aug 15 18:04:53 2010
Time Left: 110 seconds
]]
local tMatches = {}
for sIP, sMac, sDate, sSec in sString:gmatch("IP:%s([%d+\.]+)%sMAC:%s([%x+:]+)%sExpires:%s(.-)%sTime%sLeft:%s(%d+)%s%w+") do
if sIP and sMac and sDate and sSec then
print("Matched!\n"
.."IP: "..sIP.."\n"
.."MAC: "..sMac.."\n"
.."Date: "..sDate.."\n"
.."Time: "..sSec.."\n")
table.insert(tMatches, { ["IP"]=sIP, ["MAC"]=sMac, ["Date"]=sDate, ["Expires"]=sSec })
end
end
print("Total Matches: "..table.maxn(tMatches))
for k,v in ipairs(tMatches) do
print("IP Address: "..v["IP"])
end