fork(2) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.Pattern;
  5. import java.util.regex.Matcher;
  6.  
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. String regex = "(?<=^\\d{3,7})\\d(?=\\d*$)|(?<=^[A-Z]{0,6})[A-Z](?=[A-Z]*$)|\\d(?<=^\\d{2,3})(?=\\d?-\\d{5}-\\d{7}$)|\\d(?<=^\\d{3}-\\d{1,5}(?:-\\d{1,5})?)";
  12.  
  13. String s1 = "123-12345-1234567";
  14. String s2 = "AAAAAAAAA";
  15. String s3 = "12334567";
  16.  
  17. System.out.println(s1.replaceAll(regex, "*"));
  18. System.out.println(s2.replaceAll(regex, "*"));
  19. System.out.println(s3.replaceAll(regex, "*"));
  20. }
  21. }
Success #stdin #stdout 0.15s 47964KB
stdin
Standard input is empty
stdout
1**-*****-*****67
*******AA
123*****