Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
Collect values from a spreadsheet, look for those values in a string and replace

The values in my spreadsheet are these:
enter image description here

/2021/
/20212022/
/2022/
/20222023/
/2023/

To try to find these values in a string and then replace with /@@@@/ I tried creating a map:

var sheet = SpreadsheetApp.getActive().getSheetByName('One')
var liga = 'https://int.testestest.com/national/united-states/mls/2022/regular-season/r66725/'
var years = sheet.getRange('One!A10:A14').getValues().flat();
var mapObj = {one: years[0],two: years[1],three: years[2],four: years[3],five: years[4]};

var liga_substitute = liga.replace(/\b(?:one|two|three|four|five)\b/gi, matched => mapObj[matched]);

var liga_final_subs = liga_substitute.replace('one','/@@@@/').replace('two','/@@@@/').replace('three','/@@@@/').replace('four','/@@@@/').replace('five','/@@@@/')

But the result after substitution remains the same:

https://int.testestest.com/national/united-states/mls/2022/regular-season/r66725/

My final expected result is:

https://int.testestest.com/national/united-states/mls/@@@@/regular-season/r66725/

And in var liga_final_subs = exist the risk of finding these parts of text in the wrong places and replacing what shouldn't.

How should I go about doing this correctly?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Not sure what you trying to gain. Here is the code that does the job (I hope):

var liga = 'https://int.testestest.com/national/united-states/mls/2022/regular-season/r66725/'

var years = [
    '/2021/',
    '/20212022/',
    '/2022/',
    '/20222023/',
    '/2023/',
];

var liga_final_subs = liga;

years.forEach(x => liga_final_subs = liga_final_subs.replace(x, '/@@@@/'));

console.log(liga_final_subs);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda