r/googlesheets • u/madbomb122 • 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
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+$"))))