C# 正则域名

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace rexurl
{
    class Program
    {
        static void Main(string[] args)
        {
            string regex = @"(?i)http://(\w+\.){2,3}(com(\.cn)?|cn|net)\b";
            string content = "http://www.17meiman.com/u/20090313/15/5ad5d3f2-094f-4b01-9c91-a6d4052a8255.html";
            Regex re1 = new Regex(regex);
            MatchCollection matches = re1.Matches(content);
            System.Collections.IEnumerator enu = matches.GetEnumerator();

            while (enu.MoveNext() && enu.Current != null)
            {

                Match match = (Match)(enu.Current);
                string str = match.Value;
                Console.Write(str);

            }
            Console.Read();
        }
    }
}

posted on 2012-05-19 10:08  HOT SUMMER  阅读(534)  评论(0编辑  收藏  举报

导航