using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^(?:https?:\/\/)?(?:(?:[\pL0-9-]+)\.)+[\pL]{2,}(?:\/.*)?$";
string input = @"http://google.com
https://google.com
http://google.com/
https://google.com/
http://g oogle.com
http://google.com/somepath
https://g oogle.com/somepath
https://g_oogle.com/somepath
google.com
google.com/somepath
goo gle.com/badpath
кириллица.укр
кирилл ица.укр
кириллица.укр/путь
кирилл01ица.укр
кирилли-ца.укр/путь
собдомен.кириллица.укр
собдомен.кириллица.укр/путь
2саб.1саб.домен.укр
2саб.1с-аб.до мен.укр";
RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.CultureInvariant;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx