Delete Final comma in a html document

I have a situation where I have inherited an app where one of the letters is generated using html. It generates names and puts a comma after each one. The issue I have is that it puts a comma after the last name. I need to create something to delete or replace the final comma. Can you help?
2 answers

Heey Timothy,

Maybe you can try something using replaceAll or replaceFirst as described here:


Hi Timothy,

if you are certain that it always is and will be the last of the ‘,’ in the HTML and there can not be one after, you could create a custom java action with a string as input and a string as output.

public static String replaceLast(String string, String toReplace, String replacement) {
    int pos = string.lastIndexOf(toReplace);
    if (pos > -1) {
        return string.substring(0, pos)
             + replacement
             + string.substring(pos + toReplace.length(), string.length());
    } else {
        return string;


from (there also is a version with regex)


otherwise you might want to look at pattern specifiers to apply above to the substring between the HTML tags (depending on how it looks like)