如何增加字符串变量?

Tod*_*ned 2 java

我有一个字符串

String a="ABC123";
Run Code Online (Sandbox Code Playgroud)

如何增加上面的字符串,以便我得到输出:

ABC124
ABC125...and so.
Run Code Online (Sandbox Code Playgroud)

sak*_*029 5

 static final Pattern NUMBER_PATTERN = Pattern.compile("\\d+");

 static String increment(String s) {
     Matcher m = NUMBER_PATTERN.matcher(s);
     if (!m.find())
         throw new NumberFormatException();
     String num = m.group();
     int inc = Integer.parseInt(num) + 1;
     String incStr = String.format("%0" + num.length() + "d", inc);
     return  m.replaceFirst(incStr);
 }

 @Test
 public void testIncrementString() {
     System.out.println(increment("ABC123"));  // -> ABC124
     System.out.println(increment("Z00000"));  // -> Z00001
     System.out.println(increment("AB05YZ"));  // -> AB06YZ
 }
Run Code Online (Sandbox Code Playgroud)