Why Drive hands you three different URL shapes
Google Drive has never settled on a single URL format. Files opened from Drive UI look like `https://drive.google.com/file/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms/view`. Files shared via the old direct-download route look like `https://drive.google.com/uc?id=1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms`. Folders and some editor-created files (Docs, Sheets, Forms) use `https://docs.google.com/spreadsheets/d/<id>/edit` instead of the drive.google.com host. The ID itself is always the same 33-character base64url string — it is the URL shape around it that changes.
Splitting on '/' and grabbing a fixed index works until it doesn't. The moment someone pastes a folder URL or a Docs link instead of a Drive file link, your index is wrong and you get a path segment instead of an ID. The regex approach targets the ID by what precedes it — either the literal string `d/` or the query-parameter key `id=` — so the host, path depth, and trailing segments are irrelevant.