日期:2014-05-17 浏览次数:20488 次
string str = "details-1-2-3-4.html"; Match m = new Regex(@"([^-]+)(?:-([^-.]+))*").Match(str); StringBuilder sb = new StringBuilder(); sb.Append(m.Groups[1].Value).Append(".aspx?id="); for (int i = 0; i < m.Groups[2].Captures.Count - 1; i++) sb.Append(m.Groups[2].Captures[i]); sb.Append("&p=").Append(m.Groups[2].Captures[m.Groups[2].Captures.Count - 1]); Console.WriteLine(sb.ToString()); Console.ReadLine(); //details.aspx?id=123&p=4