public string GetUrlDomainName(string url)
{ //获取域名的正则表达式 string p = @"|?]*)"; Regex reg = new Regex(p, RegexOptions.IgnoreCase);//不区分大小写匹配 //正则表达式匹配结果 Match m = reg.Match(url); //返回匹配结果值 return m.Groups["domain"].Value; }
获取域名就不说了吧 下面是正则的使用
public static string getNumTonum(string str) { string regx = @"([\d]+)-([\d]+)"; string results = ""; string all = ""; Regex regex = new Regex(regx); foreach (Match m in regex.Matches(str)) { string result= m.Groups[0].ToString();/获取正则中的匹配集合 string[] rr = result.Split('-'); int fir = int.Parse(rr[0].ToString()); // int fir = int.Parse(first); int last = int.Parse(rr[1].ToString()); int s = last - fir; for (int i = fir; i <= fir + s + 1; i++) { results += i + ","; } } return results; }