假设我有一个字符串:
/first/second/third
我想删除最后一个斜杠之后的所有内容,所以我希望最终结果为:
/first/second
我该使用什么正则表达式呢?我已经尝试过以下内容:
String path = "/first/second/third";
String pattern = "$(.*?)/";
Pattern r = Pattern.compile(pattern2);
Matcher m = r.matcher(path);
if(m.find()) path = m.replaceAll("");