Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!