Looking for a regex to extract out the filename part excluding the extension from a path in this code
String filename = fullpath.replaceFirst(regex, "$1")
e.g. for starter, here is the most simple case and what I have done:
- /path/filename.ext -> filename (
fullpath.replaceFirst(".*/(.*)\\..*", "$1")
)
Here are some more advance cases that I need help with:
- /filename.ext -> filename (can start with /)
- filename. -> filename (can end with .)
- /filename -> filename (can have no .)
- filename.ext -> filename (can have no /)
- filename -> filename (can have no . and /)
- .filename -> .filename (can start with .)
- /path/.filename -> .filename (can start with . right after /)
- filename.part1.ext -> filename.part1 (can have middle .)
- /path_a/path.b/ -> (empty string) (can have no filename)
- /path_a/path.b/filename -> filename (can have . in path before /)
Edited:
There is no actual file here and the fullpath
does not lead to any file. It is coming from a URL request.