import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "0*(\\d+\\.0?\\d*?)0*(\\D|$)";
final String string = "7.315200\n"
+ "21.234400\n"
+ "20.450000\n"
+ "0.000000\n"
+ "90.0\n"
+ "0.0\n"
+ "0.500000\n"
+ "1.000000\n"
+ "20.95\n"
+ "5.3\n"
+ "0.00001\n"
+ "7.30\n"
+ "0.86603\n"
+ "0.0234501231000\n"
+ "100.0\n"
+ "000123.000456000\n"
+ "010\n"
+ "00102030.405060\n"
+ "00001.0";
final String subst = "$1$2";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html