我有这样的路径/my/long/path/which/will/never/ends/。 我想从末尾删除第二个斜线后的所有内容(因此输出将类似于/my/long/path/which/will/never/)。我怎么能那样做?我只能使用 javas String.replaceFirst 或 String.replaceAll。
谢谢
最佳答案
您可以使用:
String str = "/my/long/path/which/will/never/ends/";
str = str.replaceFirst("[^/]+/$", "");
//=> /my/long/path/which/will/never/
关于java string.replaceFirst/string.replaceLast 正则表达式从末尾删除第二个斜杠后的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31732509/