UrlRewrite正则表达式

yaoyuchiccc 2012-07-04 01:01:59
list/([^-]*)-([^-]*)-([^-]*)(?:-([^-]*))(?:-([^-]*))-([0-9]*)\.html(?:\?(.*))?

list/xxxx-xxxx-xxxx-www-www-1.html

xxxx参数必须有 www参数可有可无

满足以下3种情况·我上面的表达式该怎么改
list/xxxx-xxxx-xxxx-1.html
list/xxxx-xxxx-xxxx-www-1.html
list/xxxx-xxxx-xxxx-www-www-1.html
...全文
357 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaoyuchiccc 2012-07-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

C# code

System.IO.StreamReader reader = new System.IO.StreamReader("e:\\1.txt");
string str = reader.ReadToEnd();
Regex reg = new Regex(@"(?is)list/[^-]+-[^-]+-[……
[/Quote]
在帮我写一个啊·2楼那个不行
1 2 3 4 5 6 7
list/c1-t2-k3-b100-e200-o2-1.html

1可有可无以 c开头
2必须有 以 t开头
3必须有 以 k开头
45可有可无 b和e开头
6 可有可无 o开头
7必须有 数字就行
bdmh 2012-07-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

(?is)list/(\w+-)+\d+\.html
[/Quote]
这个不能满足,必须有三个 xxxx
licai1210 2012-07-04
  • 打赏
  • 举报
回复
    protected void Page_Load(object sender, EventArgs e)
{
List<string> urlList = new List<string>();
urlList.Add("list/xxxx-xxxx-xxxx-1.html");
urlList.Add("list/xxxx-xxxx-xxxx-www-1.html");
urlList.Add("list/xxxx-xxxx-xxxx-www-www-1.html");
string pattern = @"(?is)list/(\w+-)+\d+\.html";
Regex reg = new Regex(pattern);

foreach (string url in urlList)
{
if (reg.IsMatch(url))
{
Response.Write(url + "===匹配成功");
Response.Write("<br/>");
}
}
}
bdmh 2012-07-04
  • 打赏
  • 举报
回复

System.IO.StreamReader reader = new System.IO.StreamReader("e:\\1.txt");
string str = reader.ReadToEnd();
Regex reg = new Regex(@"(?is)list/[^-]+-[^-]+-[^-]+-([^-]+-)?([^-]+-)?[0-9]\.html");
MatchCollection mc = reg.Matches(str);
foreach (Match m in mc)
{
MessageBox.Show(m.Value);
}

62,248

社区成员

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

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

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

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