File file = new File("file-type-string-i-want-2000-01-01-01-01-01.conf.gz");
Matcher matcher = pattern.compile("\\-(.*)\\-\\d{4}")).matcher(fileName);
StringBuilder sb = new StringBuilder();
while (matcher.find()) {
sb.append(matcher.group());
}
stringList = Arrays.asList(sb.toString().split("-"));
if (stringList.size() >= 2) {
nameFragment = stringList.get(stringList.size() - 2);
}
Desired result is to extract
string-iwant
from strings that look like this
file-type-string-iwant-2000-01-01-01-01-01.conf.gz
Unfortunatly, the format for "string-iwant" is a non-fixed length of alpha-numeric characters that will include only ONE hyphen BUT never start with a hyphen. The date formatting is consistent, the year is always after the string, so my current approach is to match on the -year, but I'm having difficulty excluding the stuff at the beginning.
Thanks for any thoughts or ideas
Edit: updated strings
file-typepart, can that contain hyphen? If yes, what else makes it different fromstring-i-want?"type-string-i-want"from"string-i-want"or even from"i-want"or"want".string-i-wantalways contains a specific amount of hyphens), otherwise there is no way to tell the difference with a regexpfile-typemay or may not contain a hyphen, how do you tell apart"string-i-want"and"type-string-i-want"?