【发布时间】:2021-03-18 13:11:35
【问题描述】:
我想在 /one 和最新的斜杠之间使用正则表达式匹配字符串。 比如:
https://someurl/one/two/three.pdf -> should return one/two
https://someurl/one/two/three/four.pdf -> should return one/two/three
https://someurl/one/two/three/four/five.pdf -> should return one/two/three/four
我试过了
\b(\/dat)\B.*?(?:.)*
【问题讨论】:
-
目前没有
dat。这将匹配它https?://someurl/(\S+)/regex101.com/r/9IRnNL/1 -
你可能想要
/(one/.*)/,比如shown here。 -
或者那些
https?://[^/]*/(one/\S+)/regex101.com/r/5QazGm/1的组合 -
在 C# 中,您不需要在正则表达式模式中转义正斜杠。