Generation

generate functionMon, 14 Nov 2022

regex check if a string matches a url

public bool IsUrl(string input) { string pattern = @"^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$"; Regex reg = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); return reg.IsMatch(input); } IsUrl("https://www.google.com");

Questions about programming?Chat with your personal AI assistant