Regex strip filename from url
4 answers
As pointed out in the comments, don't use regex. Instead of this:
String url(String input) {
int slashLoc = input.lastIndexOf('/');
int underLoc = input.indexOf('_', slashLoc);
if (slashLoc != -1 && underLoc && slashLoc+1 < underLoc) { // sanity check
return input.substring(shashLoc, underLoc);
} else return "";
}
0
source to share