如何从文件URL获取路径?

Was*_*RAR -1 java regex indexing substring

我有这种格式的字符串:

file://c:/Users/....
file://E:/Windows/....
file:///f:/temp/....
file:///H:/something/....
Run Code Online (Sandbox Code Playgroud)

我怎么才能得到c:/Users/...H:/something/...

Far*_*mor 5

经过测试并将替换任意数量的斜杠.

String path = yourString.replaceFirst("file:/*", "");
Run Code Online (Sandbox Code Playgroud)

如果你只想要它匹配两个或三个斜杠

String path = yourString.replaceFirst("file:/{2,3}", "");
Run Code Online (Sandbox Code Playgroud)