Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
Append string using regex at the end of URL values inside the nested object on Node.js

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?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

let convertedObj = JSON.stringify(obj);
const fullRegex = /(url|Url)":"([^"]*)/g;
const fullMatch = convertedObj.match(fullRegex);

if(fullMatch) {
  fullMatch.forEach((str, i) => {
    convertedObj = convertedObj.replace(str, `${str}?d=1234`);
  });
}
console.log(convertedObj);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda