62,074
社区成员
发帖
与我相关
我的任务
分享
string pattern = @"^/test/([\w\W]*)*?/?$";
string tempStr = "/test/p3m3h4t4o2d1c8z4n1u4/?pmin=0&pmax=99999&amin=0&amax=99999&near=&tag=3_2&key=";
string result = Regex.Match(tempStr,pattern).Groups[1].Value;
//p3m3h4t4o2d1c8z4n1u4/?pmin=0&pmax=99999&amin=0&amax=99999&near=&tag=3_2&key=
static void Main(string[] args)
{
Func<string, string[]> getvalues = (text) =>
{
string[] txts = text.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
List<string> list = new List<string>();
MatchCollection mc = Regex.Matches(txts[1], "[a-z][0-9]+");
string[] res = new string[mc.Count];
for (int i = 0; i < mc.Count; i++)
{
list.Add(mc[i].Groups[0].Value);
}
if (txts.Length > 2)
{
if (txts[2].Contains('&'))
{
txts[2] = txts[2].Contains('?') ? txts[2].Replace("?", "") : txts[2];
txts[2].Split('&').ToList().ForEach(x => list.Add(x));
}
else
{
list.Add(txts[2]);
}
}
return list.ToArray();
};
string tex = "www.bj.com/p1a33c33d2f4g9h11m2/";
string[] p = getvalues(tex);
p.ToList().ForEach(x => Console.WriteLine(x));
Console.WriteLine("=============分割线=============");
string tex2 = "www.bj.com/p1a33c33d2f4g9h11m2/?type=bb&fac=2&d=3";
string[] p2 = getvalues(tex2);
p2.ToList().ForEach(x=>Console.WriteLine(x));
Console.Read();
}