const regex = /^"?(.+?)"?:/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^"?(.+?)"?:', 'gm')
const str = `{
id: "111",
lat: 22.2223,
lng: 4.22354,
city: "CITY",
address: "Address",
postal: "0000 AA",
phone: "000-0000000",
name: "name",
state: "",
country: "Nederland",
fax: "",
email: "",
monday: "Vanaf 1 februari: 11.00 - 17.30",
tuesday: "09:30 - 17:30",
wednesday: "09:30 - 17:30",
thursday: "09:30 - 17:30",
"friday": "09:30 - 20:00",
saturday: "09:30 - 17:00",
sunday: "gesloten",
extra_sundays: "",
"display": "true",
showonmaplink: "true",
appointment_after_6: "false",
url: "https://www.website.com",
additional_info: ""
}
`;
// 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