给定字符串:
wifi.setmode(wifi.STATION)
wifi.sta.config("ssid", "password")
wifi.sta.connect()
ledpen = 0
gpio.mode(ledpen, gpio.OUTPUT)
gpio.write(ledpen, gpio.HIGH)
pirsensorpen = 2
gpio.mode(pirsensorpen, gpio.INT, gpio.PULLUP)
function beweging() -- This function gets called when movement is detected
print("PIR sensor detecteerde beweging")
gpio.write(ledpen, gpio.LOW)
roepIFTTT(1)
tmr.alarm(0, 2000, tmr.ALARM_SINGLE, function()
gpio.write(ledpen, gpio.HIGH)
end)
end
function roepIFTTT(value1)
-- Trigger flashbutton op IFTTT
conn = nil
conn = net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) end)
conn:connect(80,"maker.ifttt.com")
conn:on("connection", function(conn, payload)
conn:send("POST /trigger/pirsensor/with/key/API_KEY?value1="..value1.." HTTP/1.1\r\nHost: maker.ifttt.com\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n") end)
conn:close()
print("IFTTT is aangeroepen")
-- It is about the code below that generates the error. If there is another way if creating a simple HTTP GET request, it is welcome.
http.get("http://httpbin.org/ip", nil, function(code, data)
if (code < 0) then
print("HTTP request failed")
else
print(code, data)
end
end)
-- coe above
end
function metingNaarThingSpeak()
local a = adc.read(0)
print("Value of moisture sensor: "..a)
local conn = nil
conn = net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) end)
conn:connect(80, "api.thingspeak.com")
conn:on("connection", function(conn, payload)
conn:send("GET /update?api_key=API_KEY&field1="..a.." HTTP/1.1\r\nHost: api.thingspeak.com\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n") end)
conn:close()
print("Meting naar ThingSpeak verzonden")
end
gpio.trig(pirsensorpen, "up", beweging)
tmr.alarm(4, 60000, tmr.ALARM_AUTO, function() metingNaarThingSpeak() end)
期望的输出
Failed entity=/data/192a7f47-84c1-445e-a615-ff82d92e2eaa/cdata/data_0;version=2181 some lorem ipsum text.
尝试
/data/192a7f47-84c1-445e-a615-ff82d92e2eaa/cdata/data_0;version=2181
我想从error.message.match(/\/data(^\s*)/)
中提取到/data/...
请指教。
答案 0 :(得分:3)
您需要将否定(^
)置于字符组([..]
)中:
/\/data([^\s]*)/
然而,这是一种提取网址的相当不安全的方法:有可能在真实网址之前和之后写入单词/data
。您应该考虑进行更加安全的测试。
答案 1 :(得分:0)
试试这个:
/^\/data+[-\/;\w=]+/g