As the title says... Chat on...

User avatar
By joe
#10938 Because (%a+) fails at the space between the first and second words. It never gets beyond that. It only matches letters, not letters and spaces.

P.S. Given the constrained memory on this device, I think you are going to have difficulties doing this kind of work on text in Lua. I don't know what your application is, but if it were me I'd look to be using a server as an intermediate processor to do the hard work for me and just send me the results.
User avatar
By joe
#10939
zooto68 wrote:I get that but what I don't get is why it stops at the " (quote) character instead of going all the way to the end of the string? Is that not classed as a character too? What is the definition of a character?


Again, because it selects the shortest match.

=string.match([["aaaaa"bbbbb"]], [["(.-)"]]) will result in finding aaaaa while string.match([["aaaaa"bbbbb"]], [["(.*)"]]) will find aaaaa"bbbbb.
User avatar
By MK1888
#10948 This works for me for openweathermap.org. I don't know why it fails DNS the first try, every time. But it extracts sunrise/sunset times.

Code: Select allwifi.setmode(wifi.STATION)
wifi.sta.config("SSID","password")

conn = nil
conn=net.createConnection(net.TCP, 0)

conn:on("receive", function(conn, pl)
      success=true
      print(pl)
      print("string search:")
      _,_,sunrise,sunset=string.find(pl,"sunrise[^0-9]+([0-9]+)[^0-9]+sunset[^0-9]+([0-9]+)")
      print("sunrise:")
      print(sunrise)
      print("sunset:")
      print(sunset)
end)

conn:on("connection", function(conn, pl)
   conn:send("GET /data/2.5/weather?q=San%20Francisco,us"
      .." HTTP/1.1\r\n"
      .."Host: api.openweathermap.org\r\n"
      .."Connection: close\r\n"
      .."Accept: */*\r\n"
      .."User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n"
      .."\r\n")
end)
                                             
conn:connect(80,'api.openweathermap.org')