3 回答

TA貢獻1853條經驗 獲得超6個贊
import java.util.regex.Matcher;
import java.util.regex.Pattern;
final String regex = "(00)*$";
final String string = "12345678\n"
+ "12400000\n"
+ "12005600\n"
+ "12340000\n"
+ "12000000\n"
+ "12340000\n"
+ "12345000";
final String subst = "";
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);
下面是結果
Substitution result: 12345678
1240
120056
1234
12
1234
123450
添加回答
舉報