读书人

求一正则

发布时间: 2013-01-11 11:57:35 作者: rapoo

求1正则 ,
string path= "http://XXX.XXXX.XXX/XXX/VIP_XX/report/aaa.aspx?id=1";
xxxx 是不可以预定的 , 红色字体内的. 固定5个字符.


result
string url="report/aaa.aspx";

很简单.就是去掉vip_XX前面的字符,跟?号后面的字符.
[解决办法]

引用:
我重新说一下返回值.
string[] strResult = Regex.XXXXX;
strResult[0] 值为 "VIP_XX"
strResult[1] 值为"report/aaa.aspx"


try...

            Regex reg = new Regex(@"(?i)(?<=/)(VIP_[^/]+)/([^?\s]+)");
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups[1].Value + "\n";
richTextBox2.Text += m.Groups[2].Value + "\n";
}

[解决办法]
string path = "http://XXX.XXXX.XXX/XXX/VIP_XX/report/aaa.aspx?id=1";
Match match = Regex.Match(path, @"/(?i)([^/]+)/(report(/[^/?]*)*)");
Response.Write(match.Groups[1].Value + "<br/>");
Response.Write(match.Groups[2].Value);

读书人网 >asp.net

热点推荐