iCode iCode - 6 months ago 34
Java Question

Find string after last underscore before dot extension

I need to find

in this string:


I tried the following to keep the string before the


I have the following to start from the last underscore:


How can I find string after last underscore before dot extension, using a regex?


RegEx is not always the best solution... :)

String pattern="PREVIMER_F2-MARS3D-MENOR1200_20140809T0000Z.nc";
int start=pattern.lastIndexOf("_") + 1;
int end=pattern.lastIndexOf(".");
if(start != 0 && end != -1 && end > start) {