简体   繁体   English

正则表达式-删除部分网址

[英]regex - deleting part of url

How can I delete with regex from URL (string) http://test.com/org/category,1/2 , this part: 如何使用正则表达式从URL(字符串) http://test.com/org/category,1/2删除,这部分是:
/2 or /2/ , with C# language /2/2/ ,使用C#语言

Of course, there will be numbers like category,1/412/ , category,1/521 , category,1/infinity.. 当然,会有数字,例如category,1/412/category,1/521category,1/infinity..

How can I do this with regex? 我该如何使用正则表达式呢?

It seems that you want to replace /\\d+/?$ with empty string. 似乎您想用空字符串替换/\\d+/?$

You could do that with: 您可以使用以下方法做到这一点:

url = Regex.Replace(url, @"/\d+/?$", "");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM