using System.Text.RegularExpressions; namespace GoogleSheetsScheduleImport; public static class SpreadsheetId { private static readonly Regex IdRegex = new( @"/spreadsheets/d/([a-zA-Z0-9-_]+)", RegexOptions.Compiled | RegexOptions.CultureInvariant); /// /// Extracts spreadsheet id from a full Google Sheets URL or returns the string if it already looks like an id. /// public static string FromUrlOrId(string input) { var trimmed = input.Trim(); var m = IdRegex.Match(trimmed); if (m.Success) return m.Groups[1].Value; if (trimmed.Length > 20 && !trimmed.Contains('/') && !trimmed.Contains(':')) return trimmed; throw new ArgumentException( "Expected a Google Sheets URL (…/spreadsheets/d/{id}/…) or a raw spreadsheet id.", nameof(input)); } }