using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"# Domain portion
([a-zA-Z0-9\-\.]+)
# Dot before the '.com', '.edu', etc.
\.
#
(com|org|me|io|net|co|edu|uk|ca|de|jp|fr|au|us|ru|ch|it|nl|se|no|es)";
string input = @"# SHOULD MATCH:
You can visit www.google.com
<b>www.google.com</b>
<b>www.google.com</b> and www.yahoo.com
http://www.google.com
www.example.co.uk
# WHAT SHOULD MATCH HERE?
www.url-with-querystring.com/?url=has-querystring
# SHOULD NOT MATCH:
www..example.com
www.example..com
www.example.zz
";
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace;
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