const regex = /((([a-zA-Z]+)(\s)*(:))){1}(\s)*(((?:[\[])?(?:["])?((.)*)(?:["])?(?:[\]]?))?)?([,]?)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('((([a-zA-Z]+)(\\s)*(:))){1}(\\s)*(((?:[\\[])?(?:["])?((.)*)(?:["])?(?:[\\]]?))?)?([,]?)', 'g')
const str = `{
id: "00000000-0000-0000-0000-000000000000",
numericId: 0,
accountId: "00000000-0000-0000-0000-000000000000",
accountCode: "",
groups: ["group1"],
isTest: true,
ftpInfo: {
host: "127.0.0.1",
port: 21,
homeDirectory: "/",
fileMask: "*.txt",
username: "",
password: "",
isPassive: true,
isBinary: true
},
contactName: "",
contactEmailAddress: "",
createdOn: "1900-01-01T00:00:00",
modifiedOn: "1900-01-01T00:00:00"
}`;
const subst = `"$3": $7$11`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
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