c# - Regex that matches with main route and filters but not matches with sub-routes
问题描述
I have to make a Regular Expression on C# that matches with the following expressions:
/videos/
/videos?filter=some%filter
/videos
But I need that this Regex does not match with expressions like:
/videos/1
/videos/67
For the moment I have the next code, but I do not really know how to complete the expression to make these matches with every word except numbers.
String currentUrl = Context.Request.Path.ToString() + Context.Request.QueryString.ToString();
String pageName = ViewContext.RouteData.Values["controller"].ToString();
Regex reg = new Regex(@"/(videos)(\/)?([^0-9])/g");
if (pageName == "Home")
{
Html.RenderPartial("Partials/_LandingNavbarPartial");
}
else if (reg.IsMatch((currentUrl.ToLower())))
{
Html.RenderPartial("Partials/_FilterNavbarPartial");
@("Matches")
}
else
{
Html.RenderPartial("Partials/_NavbarPartial");
@("Not Matches")
}
I am interested in finish my regex expression: /(videos)(\/)?([^0-9])/
解决方案
在从头开始学习 Regex 之后,我找到了下一个表达式:
(videos)\/*[^\d]*
正如我提到的那样工作,我想要。
推荐阅读
- php - 无法将循环输入字段数据从ajax发送到php
- laravel - Laravel livewire,在一个网格组件中显示两个查询的结果
- javascript - 如何将 json 数据存储到 Cypress 中的变量中
- r - R循环遍历名称特定列以检查值
- pandas - 从字典到有组织的 Excel
- php - PayPal agreement_transaction_list 为空且未更改
- flutter - 上下文弹出后的模态底页
- linux - 额外的串行端口只能工作一半:这是为什么呢?
- python - 任务中的芹菜中继消息
- azure-devops - 如何在 ADO 发布标题中包含源分支名称或拉取请求 ID?