[英]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:我必须在 C# 上创建一个与以下表达式匹配的正则表达式:
/videos/
/影片/
/videos?filter=some%filter
/videos?filter=some%filter
/videos
/视频
But I need that this Regex does not match with expressions like:但我需要这个正则表达式与以下表达式不匹配:
/videos/1
/视频/1
/videos/67
/视频/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])/
我有兴趣完成我的正则表达式:
/(videos)(\\/)?([^0-9])/
After literally learn Regex from scratch, I have found the next expression:在从头开始学习正则表达式后,我找到了下一个表达式:
(videos)\/*[^\d]*
Works as I mentioned that I wanted for.正如我提到的那样工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.