using System.Text.RegularExpressions; namespace Backend.Helper; public static partial class FilterHelper { // https://stackoverflow.com/a/56116499 private const string DomainPattern = @"^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$"; private const string TitlePattern = "(.*)"; private const string DescriptionPattern = "= end) { return ""; } return input.AsSpan().Slice(start, end - start).ToString(); } catch (Exception e) { Console.WriteLine($"start index {start} end index {end}"); Console.WriteLine(); Console.WriteLine(e); } return ""; } private static bool ValidateUrl(string url) { Regex rgx = MyRegex(); return rgx.IsMatch(url); } //Generate the RegEx at compile time. [GeneratedRegex(DomainPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled, "en-US")] private static partial Regex MyRegex(); [GeneratedRegex(TitlePattern)] private static partial Regex MyRegex1(); [GeneratedRegex(DescriptionPattern)] private static partial Regex MyRegex2(); }