const regex = /(?:\"|\')(?<key>[\w\d]+)(?:\"|\')(?:\:\s*)(?:\"|\')?(?<value>[\w\s-]*)(?:\"|\')?/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:\\"|\\\')(?<key>[\\w\\d]+)(?:\\"|\\\')(?:\\:\\s*)(?:\\"|\\\')?(?<value>[\\w\\s-]*)(?:\\"|\\\')?', 'gm')
const str = `{
"Users": {
"RCYzpiJLRkcUfaPi7Pxu1OxGFTi2": {
"Active": "ON",
"Country": "country1",
"Email": "email1",
"ID": "RCYzpiJLRkcUfaPi7Pxu1OxGFTi2",
"Img": "imglink1",
"UserName": "username1",
"videos491375": "videolink1",
"videos748628": "videolink2"
},
"ZqOOX8nUSuVYI9YY9jkub22kWTP2": {
"Active": "ON",
"Country": "country2",
"Email": "username2",
"ID": "ZqOOX8nUSuVYI9YY9jkub22kWTP2",
"Img": "imglink1",
"UserName": "username2",
"videos1096589": "videolink1",
"videos12385": "videolink2",
"videos552833": "videolink3"
},
"ZqOOX8nUSuVYI9YY9jkub22kWTP2": {
"Active": "ON",
"Country": "country3",
"Email": "email3",
"ID": "ZqOOX8nUSuVYI9YY9jkub22kWTP2",
"Img": "imglink",
"UserName": "username3",
},
"mJozWrOKLqgdUPpZhZfinIxiKy92": {
"Active": "ON",
"Country": "country4",
"Email": "emailuser",
"ID": "mJozWrOKLqgdUPpZhZfinIxiKy92",
"Img": "imglink",
"UserName": "username4",
"videos361534": "videolink1"
}
}
}`;
// 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