为了匹配一些网址,,但有一类网址我不想要的,,打比方网址如下:http://aa.xxx.com
http://bb.xxx.com
http://cc.xxx.com
...
http://img.xxx.com我要用一个正则表达式写出来,,如果碰上http://img.xxx.com 那么匹配不成功..前段时间这个问题我解决了的,,可是最近代码被我无意中删除了,,这个功能又忘掉了怎么写了,,请大家帮忙
http://bb.xxx.com
http://cc.xxx.com
...
http://img.xxx.com我要用一个正则表达式写出来,,如果碰上http://img.xxx.com 那么匹配不成功..前段时间这个问题我解决了的,,可是最近代码被我无意中删除了,,这个功能又忘掉了怎么写了,,请大家帮忙
只有 http://www.xxx.com 这样的吗?
public bool urlIsValid(string url)
{
string pattern = "http://(?<Info>.*).com";
MatchCollection matchCollection = Regex.Matches(url, pattern);
if (matchCollection.Count != 1) return true; string result = matchCollection[0].Groups["Info"].Value;
return result.Split('.').Length != 2;
}这里不对url的合法性做检查,只对http://xxx.xxx.com的格式非法检查,我的思路是取出http://和.com之间的部分,然后根据.来分隔,看是否存在1个.