remove End Zero by regex - Java java.util.regex

Java examples for java.util.regex:Match Word

Description

remove End Zero by regex

Demo Code


//package com.java2s;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static String removeEndZero(String text) {
        Pattern pattern = Pattern.compile(".0*$");
        Matcher matcher = pattern.matcher(text);
        if (matcher.find()) {
            String replace = matcher.group();
            return text.replace(replace, "");
        }/*ww  w.  j ava  2s  .c  om*/
        return text;
    }
}

Related Tutorials