iCode iCode - 1 year ago 99
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?

Answer Source

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) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download