vec <- c("http://s...content-available-to-author-only...v.scot/id/statistical-geography/S02000002",
"http://s...content-available-to-author-only...v.scot/id/statistical-geography/S02000003")
sub(".*(S\\d{8})", "\\1", vec)
dmVjIDwtIGMoImh0dHA6Ly9zLi4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi52LnNjb3QvaWQvc3RhdGlzdGljYWwtZ2VvZ3JhcGh5L1MwMjAwMDAwMiIsCiAgICAgICAgICJodHRwOi8vcy4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4udi5zY290L2lkL3N0YXRpc3RpY2FsLWdlb2dyYXBoeS9TMDIwMDAwMDMiKQpzdWIoIi4qKFNcXGR7OH0pIiwgIlxcMSIsIHZlYyk=