Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用正则表达式从 URL (string) 中删除 http://test.com/org/category,1/2,这部分: /2或/2/,使用 C# 语言
http://test.com/org/category,1/2
/2
/2/
当然,会有像category,1/412/, category,1/521,category,1/infinity..
category,1/412/
category,1/521
category,1/infinity..
我怎样才能用正则表达式做到这一点?
看来您想/\d+/?$用空字符串替换。
/\d+/?$
你可以这样做:
url = Regex.Replace(url, @"/\d+/?$", "");