Another possible solution is to use lastIndexOf , where it will look for a character or string from the return.
In my script, I had the following String and I had to extract <<UserName>>
1QAJK-WKJSH_MyApplication_Extract_<<UserName>>.arc
So, indexOf and StringUtils.substringBetween did not help, since they started looking for the character from the beginning.
So I used lastIndexOf
String str = "1QAJK-WKJSH_MyApplication_Extract_<<UserName>>.arc"; String userName = str.substring(str.lastIndexOf("_") + 1, str.lastIndexOf("."));
And it gives me
<<UserName>>
Ravi Oct 05 '17 at 18:49 2017-10-05 18:49
source share