const regex = /"temp":(.*?),/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('"temp":(.*?),', '')
const str = `{"vin":810,"vout":283,"cin":46,"cout":133,"temp":34,"charge":75,"relay":0,"pwr":3753,"vch":303,"vfl":303,"ich":40,"ifl":1,"v_relay_on":260,"v_relay_off":250,"mppt_percent":75,"snd_ena":1,"light_mode":1,"contrOn":1,"bat_lo":240,"bat_hi":297,"ssidPass":"pass","ssid":"GardenNet","iLogin":"login","iPass":"pass","cloudName":"url","cloudKey":"api_key","ApPass":"11111111","relay_mode":0,"mppt_mode":3,"st_mode":0,"refr":10,"modd":18,"eday":71,"etot":7,"sec":32,"min":59,"hour":14,"date":5,"month":1,"year":19}`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions