public class Demo {public static void main(String[] args) {String str = "1,,,2,,,3,,,,5";System.out.println(str.replaceAll(",(?=[^\\w])", ", "));}}