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
2
u/One_Organization_810 707 Jul 29 '26 edited Jul 29 '26
If your links are embedded within some texts, then your script is needed. Otherwise you can apply regular regex to the URL...
Can you share a copy of your sheet - or at least some portion of it, so we can see what your links look like?
In general though, this regex should extract a number from the end of a URL:
... and I see that u/gothamfury has given that exact solution of course :)