A regular expression to return logging.jar. Path can contain varying levels of depthness.
I think I need to use the ‘.’ operator but am unsure how to handle varying amount of slashes ?
Both below test cases should return logging.jar
C:/proj/test/tester/base/logging.jar
C:/proj/test/tester/base/leveldeeper/logging.jar
.*/([^\\.]*)\\..*in group 1 you’ll get the name of the file.extension doesn’t matter.
If you want to get name only for jar files use this pattern:
.*/([^\\.]*)\\.jar.*is a greedy regex and it will match until the last/.After/there is only file’s name with extension and you just need to get it’s name.[^\\.]*is greedy too and will match until the last dot (.), in fact what you need because the last dot is the extension separator.