Lua string.match pattern for MSN weatherservice

I am using MSN weatherservice . Now I have the following problem with string.match. All variables are filled except sWindRichtung. He is equal nil.

sHumidity, rest = string.match(rest,"humidity=\"([^\"]+)\"(.*)");
sWind, rest = string.match(rest,"windspeed=\"([^\"]+)\"(.*)");
sWindRichtung, rest = string.match(rest,"winddisplay=\"([^\"]+)\"(.*)");

String for filtering: humidity="77" winddisplay="11 km/uur N" windspeed="11"

I think character /is a problem.

+4
source share
1 answer

You can parse a string at a time. Try the following:

s = [[
humidity="77" winddisplay="11 km/uur N" windspeed="11"
]]

for k,v in s:gmatch('(%a+)="(.-)"') do
        print(k,v)
end

Of course, you can save the values ​​in a table.

+5
source

All Articles