求1正则 ,

tkscascor 2013-01-08 04:37:38
string path= "http://XXX.XXXX.XXX/XXX/VIP_XX/report/aaa.aspx?id=1";
xxxx 是不可以预定的 , 红色字体内的. 固定5个字符.


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

很简单.就是去掉vip_XX前面的字符,跟?号后面的字符.
...全文
325 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
小刘哈哈 2013-01-09
  • 打赏
  • 举报
回复
这个不错 同样遇到这样的问题 学习了
dalmeeme 2013-01-08
  • 打赏
  • 举报
回复
呵呵,不是我没认真理解,其实是你没说清楚。你在主楼说xxxxx是可变的,很明显只有VIP_XX前面部分有xxxxx。你后面在9楼又贴了http://XXX.XXXX.XXX/XXX/VIP_XX/report/XXX/aaa.aspx这个示例,其中的report也没有变化,这很容易让人误解为固定值。
tkscascor 2013-01-08
  • 打赏
  • 举报
回复
结贴. @无机之剑 . 你没认真理解,除了VIP_XX,其他全是可变的.不过谢谢你的回复.
dalmeeme 2013-01-08
  • 打赏
  • 举报
回复
		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);
-过客- 2013-01-08
  • 打赏
  • 举报
回复
引用 10 楼 tkascor 的回复:
我重新说一下返回值. 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";
            }
-过客- 2013-01-08
  • 打赏
  • 举报
回复
try...
Regex reg = new Regex(@"(?i)(?<=/)VIP_[^?\s]+");
tkscascor 2013-01-08
  • 打赏
  • 举报
回复
我重新说一下返回值. string[] strResult = Regex.XXXXX; strResult[0] 值为 "VIP_XX" strResult[1] 值为"report/aaa.aspx"
tkscascor 2013-01-08
  • 打赏
  • 举报
回复
引用 7 楼 dalmeeme 的回复:
跟XXX多少个无关。
http://XXX.XXXX.XXX/XXX/VIP_XX/report/XXX/aaa.aspx 这个就不行了. 不用正则的方式我试过好几个的.没辙才上来问正则的.
  • 打赏
  • 举报
回复
你应该有明确的匹配位置 试试
string path = "http://XXX.XXXX.XXX/XXX/VIP_XX/report/aaa.aspx?id=1";
                path = Regex.Match(path,@"(?i)(?<=/)([^\?/]+/?){3}(?=\?|$)").Value;
                //VIP_XX/report/aaa.aspx
dalmeeme 2013-01-08
  • 打赏
  • 举报
回复
跟XXX多少个无关。
tkscascor 2013-01-08
  • 打赏
  • 举报
回复
引用 5 楼 dalmeeme 的回复:
C# code?123456string path = "http://XXX.XXXX.XXX/XXX/VIP_XX/report/aaa.aspx?id=1";Uri uri = new Uri(path);string r1 = uri.Segments[uri.Segments.Length - 3].Trim('/');string r2 = uri.Segme……
这个url的XXX 不确定有多少个的
dalmeeme 2013-01-08
  • 打赏
  • 举报
回复
		string path = "http://XXX.XXXX.XXX/XXX/VIP_XX/report/aaa.aspx?id=1";
		Uri uri = new Uri(path);
		string r1 = uri.Segments[uri.Segments.Length - 3].Trim('/');
		string r2 = uri.Segments[uri.Segments.Length - 2] + uri.Segments[uri.Segments.Length - 1];
		Response.Write(r1 + "<br/>");
		Response.Write(r2);
  • 打赏
  • 举报
回复
string path = "http://XXX.XXXX.XXX/XXX/VIP_XX/report/aaa.aspx?id=1";
                path = Regex.Match(path,@"(?i)(?<=/\w{3}_\w{2}/)[^\?]+").Value;
                //report/aaa.aspx
  • 打赏
  • 举报
回复
string path = "http://XXX.XXXX.XXX/XXX/VIP_XX/report/aaa.aspx?id=1"; path = Regex.Match(path, @"[\w_]+/[\w_]+\.\w+").Value;
bdmh 2013-01-08
  • 打赏
  • 举报
回复
"[\s\S]{5}/report/aaa.aspx"
tkscascor 2013-01-08
  • 打赏
  • 举报
回复
擦, 急了. 还需要把VIP_XX 给截取出来.

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧