Q:

How to get characters in a String in Java Regardless of String size

Lets have this String for example:
"C:\Users\User\workspace\Iterator\src\Iterate_Choose.java"
"C:\Users\User\workspace\Iterator\src\testing.java"

How can I get the string just after src\ and before .java. The output should be like this:
Iterate_choose
testing

I tried looking for regex but cannot find one that matches this situation.

A:

You can use a regexp or look for the positions of the relevant parts:
    int pos1 = s.indexOf("src\\");
    int pos2 = s.lastIndexOf(".java");
    String result = s.substring(pos1 + 4, pos2);

