const regex = /"\w+":\s"?[^",{}]+"?/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('"\\w+":\\s"?[^",{}]+"?', 'gm')
const str = `{
"response": {
"first_name": "Степан",
"last_name": "Воробьёв",
"screen_name": "sparrowwwwww",
"sex": 2,
"relation": 7,
"bdate": "14.2.1995",
"bdate_visibility": 2,
"home_town": "Санкт-Петербург",
"country": {
"id": 1,
"title": "Россия"
},
"city": {
"id": 2,
"title": "Санкт-Петербург"
},
"status": "",
"phone": "+7 7** *** ** 92"
}
}`;
// 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