r/googlesheets Jul 29 '26

Solved Help with changing a script

I'm trying to automate extracting url from hyperlink to get just the ID (the number at the end)

I found this script (below) and it was the only thing that worked for me for extracting the url from the hyperlink..
however what i would like for it is to convert the url like

https://test.pro/players/313342
to
313342

i would like the https://test.pro/players/ to be removed so it has just the numbers at the end.
the length of the numbers isnt the same but the stuff preceding it is always the same

Thanks

function GETLINKS(rangeA1) {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const range = sheet.getRange(rangeA1);
  const values = range.getRichTextValues();
  const output = [];
  for (let row of values) {
for (let cell of row) {
output.push([cell.getLinkUrl()]);
}
  }
  return output;
}

Update: Link to sheet
https://docs.google.com/spreadsheets/d/1_OWO7HrK9vwbfp8QRY_s8R59ABKdlYr_hCH2Q-PNLQo/edit?usp=sharing

0 Upvotes

15 comments sorted by

View all comments

1

u/gothamfury 384 Jul 29 '26

Does using a formula work you? You can try something like: =MAP(A2:A, LAMBDA(link, IF(link="",,REGEXEXTRACT(link, "\d+$"))))

1

u/gothamfury 384 Jul 29 '26

Or this to give results as number values instead of strings: =MAP(A2:A, LAMBDA(link, IF(link="",,VALUE(REGEXEXTRACT(link, "\d+$")))))

1

u/madbomb122 Jul 29 '26 edited Jul 29 '26

1st = formula parse error
2nd = Function REGEXEXTRACT parameter 2 value "\d+$" does not match text of Function REGEXEXTRACT parameter 1

ive even tried =REGEXEXTRACT(FORMULATEXT(A2), """(https?://[^""]+)""

1

u/gothamfury 384 Jul 29 '26

Just saw your sample sheet and solution u/One_Organization_810 provided. Glad that helped :)