Java tutorial
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static String removeCommas(String text) { Pattern p = Pattern.compile("(\\d+),(\\d\\d\\d$|\\d\\d\\d\\D)"); String oldText; do { oldText = text; Matcher m = p.matcher(text); text = m.replaceAll("$1$2"); } while (oldText.equalsIgnoreCase(text) == false); return text; } }