JSFiddle - React, Tailwind, and code Playground
by VeryGoodFiddle
JavaScript
function test() {
const regex = /'([0-9a-z\-]+)': 'https:\/\/([0-9a-z\-]+)\.([0-9a-z\-]+)\.verygoodproxy\.(io|com)'/gi;
const str = "import generateLibrary from '../../-generate-library';generateLibrary({'tntsw0hd8u7': 'https://tntsw0hd8u7.sandbox.verygoodproxy.com','tntm18dkavu': 'https://tntm18dkavu.sandbox.verygoodproxy.com','live': 'https://trim.live.verygoodproxy.com','tntygkbfvxg': 'https://tntygkbfvxg.sandbox.verygoodproxy.com','tntqqagpwez': 'https://tntqqagpwez.sandbox.verygoodproxy.com','tnttuogmelv': 'https://tnttuogmelv.sandbox.verygoodproxy.com','tntmrxblvlt': 'https://tntmrxblvlt.sandbox.verygoodproxy.com','tntqolsgkl9': 'https://tntqolsgkl9.sandbox.verygoodproxy.com','tntuwv1ux1h': 'https://tntuwv1ux1h.sandbox.verygoodproxy.com','tntuv6z8m7q': 'https://tntuv6z8m7q.sandbox.verygoodproxy.com','tntrgqghjzf': 'https://tntrgqghjzf.sandbox.verygoodproxy.com'});";
console.log(regex.exec(str));
let m;
let update = [];
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
let tenant = { ignoreCommit: true };
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(match, groupIndex);
if (groupIndex === 1) {
tenant.tenantIdentifier = match;
}
if (groupIndex === 3) {
tenant.tenantEnvironment = match;
}
tenant.tenantHost = 'verygoodproxy.com';
});
update.push(tenant);
//console.log(update);
}
//reset regular expresion
regex.lastIndex = 0;
}
test();