const regex = /"([^"]+)":/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('"([^"]+)":', 'g')
const str = `{
"activity:status": "BOOKED",
"criteria:duration": 8,
"criteria:tripFrom": 1500242400,
"criteria:tripTo": 1500933600,
"intent:booker": 0.06258322237017303,
"intent:churnRisk": 0.3004193725304727,
"intent:churnRiskText": "LOW",
"intent:userClass": "CUSTOMER",
"issues:acs": 14,
"issues:total": 0,
"revenue": 2896,
"tracking:events": 162,
"tracking:firstVisit": 1475320136,
"tracking:lastVisit": 1498054362,
"tracking:sessions30": 19,
"tracking:timeSpent": 10603,
"value:potentialRevenue": {
"mean": 2880.5258186397987,
"stddev": 504.1184773012633,
"weight": 1,
"confidence": 1
},
"criteria:occupancy": {
"adults": 2,
"children": 2,
"infants": 0
}
}`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// 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