fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. List<String> strs = Arrays.asList("ABC/1111111031111111/0318*12345678",
  11. "ABC/1111111031111111/1120*12345678");
  12. String pattern = "(/\\d{12,19}/)(?:0[1-9]|1[0-2])\\d{2}(\\*)";
  13. for (String str : strs)
  14. System.out.println(str + " => " + str.replaceAll(pattern, "$11222$2"));
  15.  
  16. }
  17. }
Success #stdin #stdout 0.18s 50564KB
stdin
Standard input is empty
stdout
ABC/1111111031111111/0318*12345678 => ABC/1111111031111111/1222*12345678
ABC/1111111031111111/1120*12345678 => ABC/1111111031111111/1222*12345678