Sample object (the below object is a very large nested object):
const obj = { a: 1, url: "https://someurl.com", b: { c: 1, d: { otherUrl: "https://someotherurl.com"}};
I want to append some query parameter at the end of each URL, like ?d=1234
.
I tried to do it, but the URLs are changed:
const convertedObj = JSON.stringify(obj);
let bufferObj;
const fullRegex = /url":"([^"]*)/g;
const fullMatch = convertedObj.match(fullRegex);
if(fullMatch) {
fullMatch.forEach((str, i) => {
bufferObj = convertedObj.replace(/(url|Url)":"([^"]*)/g, `${str}?d=1234`);
});
}
Is there a solution for this in Node.js using regex?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment