Sahil :
I have input string:
String myString = "test, test1, must not be null";
I want to remove last comma in this string
Expected output:
test, test1 must not be null
Any idea if this can be done using StringUtils?
Tim Biegeleisen :
Here is one option which uses a negative lookahead to target the final comma in the string:
String myString = "test, test1, must not be null";
myString = myString.replaceAll(",(?!.*,)", "");
System.out.println(myString);
test, test1 must not be null