0
Ich kann nicht herausfinden, warum dies beide Vorkommen der Zeichenfolge /Most recent instantaneous value: ([^ ]+) /
Ich brauche nur die erste Übereinstimmung.Regex alle Vorkommen zurückgeben, ich brauche nur die erste
var http = require("http");
var options = {
host: 'waterdata.usgs.gov',
port: 80,
path: '/ga/nwis/uv?cb_72036=on&cb_00062=on&format=gif_default&period=1&site_no=02334400'
};
function extract (body, cb) {
if(!body)
return;
var matches=body.match(/Most recent instantaneous value: ([^ ]+) /);
if(matches)
cb(matches[1]);
}
http.get(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
extract(chunk, function(v){ console.log(v); });
});
}).on('error', function(e) {
console.log('problem with request: ' + e.message);
});
Ich nehme an, es sind mehrere on'data' Veranstaltungen. Übrigens könntest du 'extract (chunk, console.log);' schreiben – kirilloid