The sample below should work for you, provided that:
- IP address is dotted decimal notation.
- The MAC address is hexadecimal, separated by colons.
Note. The MAC address provided in your question has a βGβ which is not a hexadecimal digit.
Edit: Thinking about your question in detail, I expanded my answer to show how multiple instances can be captured in a table.
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
source share