Regex is your friend :
public static void main(String[] args) throws Exception {
String s1 = "jdK1TESTds3TEST";
System.out.println(s1.replaceAll("(?i)(.*)TEST$", "$1"));
}
O/P : jdK1TESTds3
The code above replaces the last TEST (if it exists). Add (?i)
modifier to make it case-insenstive.
4
solved Checking of String if it has this specific value [closed]