正则表达式匹配 网站首页地址例如: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/
http://\S+\.*/
可是得到的结果是 http://forum.csdn.net/PointForum/Forum/
或者
http://.*?/
用非贪婪模式
参考:http://hi.csdn.net/link.php?url=http://blog.csdn.net%2Flxcnn
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 . . .