using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^(https?:\/\/)?([\w\Q$-_+!*'(),%\E]+\.)+(\w{2,63})(:\d{1,4})?([\w\Q/$-_+!*'(),%\E]+\.?[\w])*\/?$";
string input = @"http://google.com
https://google.com
http://www.google.com
www.google.com
www.google.de:8080
www.test123.de
www.domain.com.de.whatever.to
www.google
h4xx0!2.net
page.to
hallo.to/test/whatever
hallo.to/test/whatever.cgi
www.google.com/startpage.html/
www.google.!!!
www..com
http://blabla.computer.de/.......................";
RegexOptions options = RegexOptions.Multiline;
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