正则表达式匹配 网站首页地址例如:http://forum.csdn.net/PointForum/Forum/PostTopic.aspx?forumID=e2798a59-79d5-4833-9c57-87d46a8b907a需要的结果:http://forum.csdn.net/这个是我写的
http://\S+\.*/
可是得到的结果是 http://forum.csdn.net/PointForum/Forum/

解决方案 »

  1.   

    直接substing就可以了,感觉这样的弄正则没多大意义
      

  2.   

    http://\S+?\.*?/
    或者
    http://.*?/
      

  3.   

    对的,要加上?  
    用非贪婪模式
    参考:http://hi.csdn.net/link.php?url=http://blog.csdn.net%2Flxcnn
      

  4.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str = "http://forum.csdn.net/PointForum/Forum/PostTopic.aspx?forumID=e2798a59-79d5-4833-9c57-87d46a8b907a";
                Regex re = new Regex(@"http://.*?/");
                Console.WriteLine(re.Match(str).Value);
            }
        }
    }http://forum.csdn.net/
    Press any key to continue . . .